Merge pull request #277 from isildur-g/wip-cppcheck271

phase 1 of addressing cppcheck useStlAlgorithm warnings for fill and copy operations
This commit is contained in:
Konstantinos Margaritis
2024-05-15 10:44:15 +03:00
committed by GitHub
19 changed files with 102 additions and 98 deletions

View File

@@ -455,11 +455,10 @@ void cleanupPositions(vector<PositionInfo> &a) {
vector<PositionInfo> out;
out.reserve(a.size()); // output should be close to input in size.
for (const auto &p : a) {
if (seen.emplace(p.pos, p.flags).second) {
out.emplace_back(p); // first encounter
}
}
auto seens = [&seen=seen](const PositionInfo &p) {
return (seen.emplace(p.pos, p.flags).second);
};
std::copy_if(begin(a), end(a), std::back_inserter(out), seens);
DEBUG_PRINTF("in %zu; out %zu\n", a.size(), out.size());
a.swap(out);