Skip to content

Commit 23279b8

Browse files
committed
Switch to manual lambdas
1 parent 48789ef commit 23279b8

File tree

1 file changed

+34
-11
lines changed

1 file changed

+34
-11
lines changed

avida-core/source/actions/PopulationActions.cc

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5289,9 +5289,14 @@ class cActionKillDemesHighestParasiteLoad : public cAction
52895289
std::vector<int> deme_indices(num_demes);
52905290
std::iota(std::begin(deme_indices), std::end(deme_indices), 0);
52915291

5292+
struct HasAny {
5293+
cPopulation& pop;
5294+
HasAny(cPopulation& pop) : pop(pop) {}
5295+
bool operator()(const int d){ return not pop.GetDeme(d).IsEmpty(); }
5296+
};
52925297
const int num_eligible = std::count_if(
52935298
std::begin(deme_indices), std::end(deme_indices),
5294-
[&](const int d) { return not pop.GetDeme(d).IsEmpty(); }
5299+
HasAny(pop)
52955300
);
52965301
const int binomial_draw = ctx.GetRandom().GetRandBinomial(
52975302
num_eligible,
@@ -5302,26 +5307,44 @@ class cActionKillDemesHighestParasiteLoad : public cAction
53025307
std::cout << "warning: capped kill quota at " << kill_quota << " from " << binomial_draw << " binomial sample with " << num_eligible << " eligible and kill prob " << m_killprob << std::endl;
53035308
}
53045309

5310+
struct GetParasiteLoad {
5311+
cPopulation& pop;
5312+
GetParasiteLoad(cPopulation& pop) : pop(pop) {}
5313+
double operator()(const int d){ return pop.GetDeme(d).GetParasiteLoad(); }
5314+
};
53055315
std::vector<double> parasite_loads(num_demes);
53065316
std::transform(
53075317
std::begin(deme_indices), std::end(deme_indices),
53085318
std::begin(parasite_loads),
5309-
[&](const int d) { return pop.GetDeme(d).GetParasiteLoad(); }
5319+
GetParasiteLoad(pop)
53105320
);
53115321

5312-
std::partial_sort(
5313-
std::begin(deme_indices),
5314-
std::next(std::begin(deme_indices), kill_quota),
5315-
std::end(deme_indices),
5316-
[&](const int d1, const int d2) {
5317-
return parasite_loads[d1] > parasite_loads[d2];
5322+
struct Comp {
5323+
std::vector<double>& loads;
5324+
Comp(std::vector<double> &loads) : loads(loads) {}
5325+
bool operator()(const int d1, const int d2) {
5326+
return loads[d1] > loads[d2];
53185327
}
5319-
);
5320-
5328+
};
5329+
std::partial_sort(
5330+
std::begin(deme_indices),
5331+
std::next(std::begin(deme_indices), kill_quota),
5332+
std::end(deme_indices),
5333+
[&](const int d1, const int d2)
5334+
{
5335+
return parasite_loads[d1] > parasite_loads[d2];
5336+
});
5337+
5338+
struct DoKill {
5339+
cPopulation& pop;
5340+
cAvidaContext& ctx;
5341+
DoKill(cPopulation& pop, cAvidaContext& ctx) : pop(pop), ctx(ctx) {}
5342+
void operator()(const int d) { pop.GetDeme(d).KillAll(ctx); }
5343+
};
53215344
std::for_each(
53225345
std::begin(deme_indices),
53235346
std::next(std::begin(deme_indices), kill_quota),
5324-
[&](const int d) { pop.GetDeme(d).KillAll(ctx); }
5347+
DoKill(pop, ctx)
53255348
);
53265349

53275350
} // End Process()

0 commit comments

Comments
 (0)