From c13864bfc0bbbf34fe6cf8e9a304937043757292 Mon Sep 17 00:00:00 2001 From: Spartan322 Date: Tue, 30 Dec 2025 15:10:48 -0500 Subject: [PATCH] Add strict_regular_invocable_r to concepts Prefer strict_regular_invocable_r for IndexedFlatMap callables arguments --- src/openvic-simulation/core/template/Concepts.hpp | 6 ++++++ src/openvic-simulation/types/IndexedFlatMap.hpp | 8 ++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/openvic-simulation/core/template/Concepts.hpp b/src/openvic-simulation/core/template/Concepts.hpp index 3063bfb9..1c7193cd 100644 --- a/src/openvic-simulation/core/template/Concepts.hpp +++ b/src/openvic-simulation/core/template/Concepts.hpp @@ -226,4 +226,10 @@ namespace OpenVic { concept mul_add_assignable = requires(Lhs& lhs, const A a, const B b) { { lhs += a * b } -> std::same_as; }; + + // Return type is strictly evaluated with same_as + template + concept strict_regular_invocable_r = std::regular_invocable && requires(F f, Args&&... args) { + { f(static_cast(args)...) } -> std::same_as; + }; } diff --git a/src/openvic-simulation/types/IndexedFlatMap.hpp b/src/openvic-simulation/types/IndexedFlatMap.hpp index 051defad..a1af1048 100644 --- a/src/openvic-simulation/types/IndexedFlatMap.hpp +++ b/src/openvic-simulation/types/IndexedFlatMap.hpp @@ -604,7 +604,7 @@ namespace OpenVic { * * @note This method requires `ValueType` to be copy-assignable. */ - void reinitialize_with_generator(fu2::function value_generator) + void reinitialize_with_generator(strict_regular_invocable_r auto&& value_generator) requires std::copyable { for (iterator it = begin(); it < end(); it++) { auto& [key, value] = *it; @@ -622,7 +622,7 @@ namespace OpenVic { * @note This method destroys existing elements and constructs new ones in place, * which is often more efficient for move-only types. */ - void reinitialize_with_generator(fu2::function value_generator) + void reinitialize_with_generator(strict_regular_invocable_r auto&& value_generator) requires std::movable && (!std::copyable) { values.clear(); for (ForwardedKeyType const& key : keys) { @@ -735,7 +735,7 @@ namespace OpenVic { template IndexedFlatMap divide_handle_zero( IndexedFlatMap const& other, - fu2::function handle_div_by_zero + strict_regular_invocable_r auto&& handle_div_by_zero ) const requires divisible { static_assert(has_index); if (!check_subset_span_match(other)) { @@ -745,7 +745,7 @@ namespace OpenVic { return IndexedFlatMap(keys, [&](ForwardedKeyType const& key) { if (other.contains(key)) { if (other.at(key) == static_cast(0)) { - return handle_div_by_zero( + return std::forward(handle_div_by_zero)( this->at(key), other.at(key) );