Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 028fbc3

Browse files
committed
using std::erase_if instead of iterator loop
1 parent 579fe6e commit 028fbc3

1 file changed

Lines changed: 9 additions & 10 deletions

File tree

plugins/preserve-tombs.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -222,28 +222,27 @@ static void update_tomb_assignments(color_ostream &out) {
222222

223223
}
224224

225-
// now check our civzones for unassignment / deleted zone /
226-
for (auto it = tomb_assignments.begin(); it != tomb_assignments.end(); ++it){
227-
auto &[unit_id, building_id] = *it;
225+
// now check our civzones for unassignment / deleted zone
226+
std::erase_if(tomb_assignments,[&](const auto& p){
227+
auto &[unit_id, building_id] = p;
228228

229229
const int tomb_idx = binsearch_index(world->buildings.other.ZONE_TOMB, building_id);
230230
if (tomb_idx == -1) {
231231
out.print("%s tomb missing: %d - removing\n", plugin_name, building_id);
232-
it = tomb_assignments.erase(it);
233-
continue;
232+
return true;
234233
}
235234
const auto tomb = virtual_cast<df::building_civzonest>(world->buildings.other.ZONE_TOMB[tomb_idx]);
236235
if (!tomb || !tomb->flags.bits.exists) {
237236
out.print("%s tomb missing: %d - removing\n", plugin_name, building_id);
238-
it = tomb_assignments.erase(it);
239-
continue;
237+
return true;
240238
}
241239
if (tomb->assigned_unit_id != unit_id) {
242240
out.print("%s unassigned unit %d from tomb %d - removing\n", plugin_name, unit_id, building_id);
243-
it = tomb_assignments.erase(it);
244-
continue;
241+
return true;
245242
}
246-
}
243+
244+
return false;
245+
});
247246

248247
}
249248

0 commit comments

Comments
 (0)