[DnaReplicationReport] Factor the loops over the 3 mutation types
Throughout the post-treatments, there is a pattern to iterate over all
mutations contained in the DnaReplicationReport
of individuals.
As these are split into 3 std::list
s of different types, the body of the
loop is usually repeated 3 times (once for each list), which is prone to
mistakes and hard to update if we want to add a new mutation type.
This commit factors this code by introducing a higher-order template
method named DnaReplicationReport::iter_muts(f)
, which takes a function
f
and runs f(mut)
for all mutations mut in the 3 lists.
This replaces the existing code very easily by turning the loop bodies
into a single lambda block, and allows us to change the code in one
single place (iter_muts()
) if we want to introduce more mutation types.
Moreover, as the function iter_muts(f)
is compiled once for each call with a
different function f
, and can be inlined, there should be no performance hit
compared to the original loops.