OpenMS
OpenMS copied to clipboard
Convert iterator for loops
To range for loops for easier readability. Many have already been converted but some still remain.
Hi, Can I contribute to this please?
Sure. Maybe start with a few of them and make a small Pull request so we can give feedback if you are on the right track.
maybe a few things to consider:
- prefer
const autoover justautoif the variable does not need to be modified. - use
autoif the type is small (roughly 16 bytes or less) , and you do not need to modify the container. Otherwise useauto&, i.e. take by reference, to avoid the copy (or enable modification). Points 1) and 2) can be combined, e.g.const auto&. - use sensible names, e.g. if the former name of the variable using iterators was
it(as it usually is), then you should find a better name (sinceitsuggests an iterator, whereas the new range-based loop variable should be named like the type that underlies the variable, e.g.spec(for MSSpectrum) orp(for a Peak1D).
made-up example: Old:
for (MSExperiment::Iterator it = exp.begin(); it != exp.end(); ++it)
{
it->setRT(0.0);
}
becomes (new)
for (auto& spec : exp)
{
spec.setRT(0.0);
}
is this issue still open.can i have a look into it.
There is already anboten PR. Thanks!