From 0cf5d1c96884a5812a27da634e9c0c92331012d9 Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Fri, 15 Dec 2023 14:03:08 +0100 Subject: [PATCH] #4084 debug iterator failure --- src/ifcgeom/taxonomy.h | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/ifcgeom/taxonomy.h b/src/ifcgeom/taxonomy.h index b0392d73ce..eae30e1069 100644 --- a/src/ifcgeom/taxonomy.h +++ b/src/ifcgeom/taxonomy.h @@ -1264,14 +1264,16 @@ typedef item const* ptr; // @nb traverses nested collections template taxonomy::collection::ptr filter_in_place(taxonomy::collection::ptr collection, Fn fn) { - for (auto it = --collection->children.end(); it >= collection->children.begin(); --it) { - if (!apply_predicate_to_collection(*it, fn)) { + const auto& c = collection->children; + auto new_end = std::remove_if(c.begin(), c.end(), [fn](taxonomy::geom_item::ptr i) { + return !apply_predicate_to_collection(i, fn); + }); #ifdef TAXONOMY_USE_NAKED_PTR - delete* it; -#endif - collection->children.erase(it); - } + for (auto it = new_end; it != c.end(); ++it) { + delete *it; } +#endif + c.erase(new_end, c.end()); return collection; }