| 1700 | // @nb traverses nested collections |
| 1701 | template <typename Fn> |
| 1702 | taxonomy::collection::ptr filter(const taxonomy::collection::ptr& collection, Fn fn) { |
| 1703 | auto filtered = taxonomy::make<taxonomy::collection>(); |
| 1704 | for (auto& child : collection->children) { |
| 1705 | if (apply_predicate_to_collection(child, fn)) { |
| 1706 | filtered->children.push_back(clone(child)); |
| 1707 | } |
| 1708 | } |
| 1709 | if (filtered->children.empty()) { |
| 1710 | #ifdef TAXONOMY_USE_NAKED_PTR |
| 1711 | delete filtered; |
| 1712 | #endif |
| 1713 | return nullptr; |
| 1714 | } |
| 1715 | return filtered; |
| 1716 | } |
| 1717 | |
| 1718 | // @nb traverses nested collections |
| 1719 | template <typename Fn> |