Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/openvic-simulation/core/template/Concepts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Lhs&>;
};

// Return type is strictly evaluated with same_as
template<typename F, typename Return, typename... Args>
concept strict_regular_invocable_r = std::regular_invocable<F, Args...> && requires(F f, Args&&... args) {
{ f(static_cast<Args>(args)...) } -> std::same_as<Return>;
};
}
8 changes: 4 additions & 4 deletions src/openvic-simulation/types/IndexedFlatMap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ namespace OpenVic {
*
* @note This method requires `ValueType` to be copy-assignable.
*/
void reinitialize_with_generator(fu2::function<ValueType(ForwardedKeyType const&)> value_generator)
void reinitialize_with_generator(strict_regular_invocable_r<ValueType, ForwardedKeyType const&> auto&& value_generator)
requires std::copyable<ValueType> {
for (iterator it = begin(); it < end(); it++) {
auto& [key, value] = *it;
Expand All @@ -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<ValueType(ForwardedKeyType const&)> value_generator)
void reinitialize_with_generator(strict_regular_invocable_r<ValueType, ForwardedKeyType const&> auto&& value_generator)
requires std::movable<ValueType> && (!std::copyable<ValueType>) {
values.clear();
for (ForwardedKeyType const& key : keys) {
Expand Down Expand Up @@ -735,7 +735,7 @@ namespace OpenVic {
template <typename OtherValueType>
IndexedFlatMap<ForwardedKeyType, ValueType> divide_handle_zero(
IndexedFlatMap<ForwardedKeyType,OtherValueType> const& other,
fu2::function<ValueType(ValueType const&, OtherValueType const&)> handle_div_by_zero
strict_regular_invocable_r<ValueType, ValueType const&, OtherValueType const&> auto&& handle_div_by_zero
) const requires divisible<ValueType,OtherValueType,ValueType> {
static_assert(has_index<ForwardedKeyType>);
if (!check_subset_span_match(other)) {
Expand All @@ -745,7 +745,7 @@ namespace OpenVic {
return IndexedFlatMap(keys, [&](ForwardedKeyType const& key) {
if (other.contains(key)) {
if (other.at(key) == static_cast<ValueType>(0)) {
return handle_div_by_zero(
return std::forward(handle_div_by_zero)(
this->at(key),
other.at(key)
);
Expand Down