Bugfix: Avoid possible use of out-of-scope temporary.

Since std::clamp returns a reference we must be careful to not capture
the return value by reference, when there is a temporary among the input
parameters.

For the second change (adding the explicit Scalar return type to a lambda)
this is strictly speaking not necessary, as the lambda's return type is not
a reference, but that is obscure so the change is just done as to clarify.
This commit is contained in:
Atgeirr Flø Rasmussen
2024-05-28 16:01:48 +02:00
parent c84f14042d
commit 0fe76f6011
2 changed files with 2 additions and 2 deletions

View File

@@ -338,7 +338,7 @@ copyToWellState(const MultisegmentWellGeneric<Scalar>& mswell,
std::transform(segments.phase_resv_rates.begin() + (seg + 0) * well_.numPhases(),
segments.phase_resv_rates.begin() + (seg + 1) * well_.numPhases(),
segments.phase_holdup.begin() + (seg + 0) * well_.numPhases(),
[tot_resv](const auto qr) { return std::clamp(qr / tot_resv, 0.0, 1.0); });
[tot_resv](const auto qr) -> Scalar { return std::clamp(qr / tot_resv, 0.0, 1.0); });
// 4) Local condition flow velocities for segments other than top segment.
if (seg > 0) {