summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2025-03-23 15:25:03 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2025-03-23 15:25:03 +0000
commit5f12ed9f259a825efc7c2354230932712273fab6 (patch)
tree5a2d24e651e107ed6bacb4ec363126be44c97b74 /lib
parentOther objects support in removeAll/clear (diff)
downloadilt-5f12ed9f259a825efc7c2354230932712273fab6.tar.bz2
ilt-5f12ed9f259a825efc7c2354230932712273fab6.tar.xz
ilt-5f12ed9f259a825efc7c2354230932712273fab6.zip
Use otherObjects where possible for find
Diffstat (limited to 'lib')
-rw-r--r--lib/collection.h32
1 files changed, 26 insertions, 6 deletions
diff --git a/lib/collection.h b/lib/collection.h
index 98f043b..6ee6c82 100644
--- a/lib/collection.h
+++ b/lib/collection.h
@@ -54,12 +54,19 @@ public:
T *
find()
{
- if (auto i = std::find_if(objects.begin(), objects.end(),
- [](auto && o) {
- return (dynamic_cast<T *>(o.get()));
- });
- i != objects.end()) {
- return static_cast<T *>(i->get());
+ const auto & srcObjects = containerFor<T>();
+ if constexpr (std::is_convertible_v<typename std::remove_reference_t<decltype(srcObjects)>::value_type, T *>) {
+ if (srcObjects.empty()) {
+ return nullptr;
+ }
+ return srcObjects.front();
+ }
+ else if (auto i = std::find_if(srcObjects.begin(), srcObjects.end(),
+ [](auto && o) {
+ return dynamic_cast<T *>(std::to_address(o)) != nullptr;
+ });
+ i != srcObjects.end()) {
+ return static_cast<T *>(std::to_address(*i));
}
return nullptr;
}
@@ -224,6 +231,19 @@ protected:
...);
}
+ template<typename T>
+ [[nodiscard]]
+ const auto &
+ containerFor() const
+ {
+ if constexpr ((std::is_convertible_v<T *, Others *> || ...)) {
+ return std::get<OtherObjects<T>>(otherObjects);
+ }
+ else {
+ return objects;
+ }
+ }
+
template<typename T = Object, typename... Params>
auto
apply_internal(const auto begin, const auto end, const auto & m, Params &&... params) const