diff options
Diffstat (limited to 'lib/collection.h')
-rw-r--r-- | lib/collection.h | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/lib/collection.h b/lib/collection.h index 853b982..5f39e71 100644 --- a/lib/collection.h +++ b/lib/collection.h @@ -115,14 +115,24 @@ public: } template<typename T> - requires(std::is_convertible_v<T *, Others *> || ...) + requires std::is_base_of_v<Object, T> auto removeAll() { - std::get<OtherObjects<T>>(otherObjects).clear(); - return std::erase_if(objects, [](auto && op) { - return dynamic_cast<T *>(op.get()); - }); + auto removeAllFrom = [](auto & container) { + if constexpr (std::is_base_of_v<T, decltype(std::to_address(container.front()))>) { + const auto size = container.size(); + container.clear(); + return size; + } + else { + return std::erase_if(container, [](auto && objPtr) -> bool { + return dynamic_cast<const T *>(std::to_address(objPtr)); + }); + } + }; + (removeAllFrom(std::get<OtherObjects<Others>>(otherObjects)), ...); + return removeAllFrom(objects); } void |