Update unused filter() function

This commit is contained in:
Thomas Krijnen
2023-07-31 16:01:29 +08:00
parent 73fdeaf2a7
commit b7f73153cc
+4 -2
View File
@@ -1189,15 +1189,17 @@ T* dcast(const U*& u) {
// @nb traverses nested collections // @nb traverses nested collections
template <typename Fn> template <typename Fn>
taxonomy::collection::ptr filter(taxonomy::collection* collection, Fn fn) { taxonomy::collection::ptr filter(taxonomy::collection::ptr collection, Fn fn) {
auto filtered = new taxonomy::collection; auto filtered = taxonomy::make<taxonomy::collection>();
for (auto& child : collection->children) { for (auto& child : collection->children) {
if (apply_predicate_to_collection(child, fn)) { if (apply_predicate_to_collection(child, fn)) {
filtered->children.push_back(clone(child)); filtered->children.push_back(clone(child));
} }
} }
if (filtered->children.empty()) { if (filtered->children.empty()) {
#ifdef TAXONOMY_USE_NAKED_PTR
delete filtered; delete filtered;
#endif
return nullptr; return nullptr;
} }
return filtered; return filtered;