diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2025-03-23 18:46:10 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2025-03-23 18:46:10 +0000 |
commit | 7b44e4f20b91a64b778bcc8b2f00602d4ba13bd2 (patch) | |
tree | 0c8dc333e6a8ffd34ae5675910029d45483166db /lib | |
parent | Use typed collections for apply/applyOne (diff) | |
download | ilt-7b44e4f20b91a64b778bcc8b2f00602d4ba13bd2.tar.bz2 ilt-7b44e4f20b91a64b778bcc8b2f00602d4ba13bd2.tar.xz ilt-7b44e4f20b91a64b778bcc8b2f00602d4ba13bd2.zip |
Support using typed collections for subclass filtering
Diffstat (limited to 'lib')
-rw-r--r-- | lib/collection.h | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/lib/collection.h b/lib/collection.h index d32cff1..b786e2f 100644 --- a/lib/collection.h +++ b/lib/collection.h @@ -236,12 +236,21 @@ protected: } template<typename T> + requires((std::is_convertible_v<T *, Others *> || ...)) + [[nodiscard]] consteval static bool + idx() + { + size_t typeIdx = 0; + return ((typeIdx++ && std::is_convertible_v<Others *, T *>) || ...); + } + + template<typename T> [[nodiscard]] - const auto & + constexpr const auto & containerFor() const { if constexpr ((std::is_convertible_v<T *, Others *> || ...)) { - return std::get<OtherObjects<T>>(otherObjects); + return std::get<idx<T>()>(otherObjects); } else { return objects; @@ -260,7 +269,7 @@ protected: } else { return std::count_if(begin, end, [&m, ¶ms...](auto && op) { - if (auto o = dynamic_cast<T *>(op.get())) { + if (auto o = dynamic_cast<T *>(std::to_address(op))) { std::invoke(m, o, std::forward<Params>(params)...); return true; } @@ -280,7 +289,7 @@ protected: } else { return std::find_if(begin, end, [&m, ¶ms...](auto && op) { - if (auto o = dynamic_cast<T *>(op.get())) { + if (auto o = dynamic_cast<T *>(std::to_address(op))) { return std::invoke(m, o, std::forward<Params>(params)...); } return false; |