Use try_emplace() instead of emplace()

Fix bug where emplace() did not update existing keys in the map.
Instead use try_emplace() for efficient conditional construction and
assignment.
This commit is contained in:
Håkon Hægland committed 2025-06-22 12:09:14 +02:00
1 parent aee9658269
commit 61e5a3dd7f
1 file changed
+5 -2
+5 -2
View File
@@ -514,9 +514,12 @@ void GroupState<Scalar>::
update_group_production_potential(const std::string& gname, Scalar oil_rate,
Scalar gas_rate, Scalar water_rate)
{
this->production_group_potentials.emplace(
gname, GroupPotential{oil_rate, gas_rate, water_rate}
auto [it, inserted] = production_group_potentials.try_emplace(
gname, oil_rate, gas_rate, water_rate
);
if (!inserted) {
it->second = GroupPotential{oil_rate, gas_rate, water_rate};
}
}
template<class Scalar>