summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2025-03-28 01:20:16 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2025-03-28 03:00:35 +0000
commit014373a9ef99e4c9cc1c15f52e0946ea413c868d (patch)
tree4c4339ac49add51fbc09fa74b9fe65af9c35cf9b
parentAdd standard special members (diff)
downloadilt-014373a9ef99e4c9cc1c15f52e0946ea413c868d.tar.bz2
ilt-014373a9ef99e4c9cc1c15f52e0946ea413c868d.tar.xz
ilt-014373a9ef99e4c9cc1c15f52e0946ea413c868d.zip
Expose size of each container by type
-rw-r--r--lib/collection.h8
-rw-r--r--test/test-collection.cpp8
2 files changed, 12 insertions, 4 deletions
diff --git a/lib/collection.h b/lib/collection.h
index 91a36c2..22dcc52 100644
--- a/lib/collection.h
+++ b/lib/collection.h
@@ -35,6 +35,14 @@ public:
return objects[idx];
}
+ template<typename T = Object>
+ requires(std::is_same_v<T, Object> || (std::is_base_of_v<Others, T> || ...))
+ [[nodiscard]] auto
+ size() const noexcept
+ {
+ return containerFor<T>().size();
+ }
+
template<typename T = Object, typename... Params>
auto
create(Params &&... params)
diff --git a/test/test-collection.cpp b/test/test-collection.cpp
index b0f2c43..620d3ab 100644
--- a/test/test-collection.cpp
+++ b/test/test-collection.cpp
@@ -320,10 +320,10 @@ BOOST_AUTO_TEST_CASE(addMulti)
BOOST_CHECK_EQUAL(std::get<1>(otherObjects).size(), 3);
BOOST_CHECK_EQUAL(std::get<2>(otherObjects).size(), 0);
create<Multi>();
- BOOST_CHECK_EQUAL(objects.size(), 5);
- BOOST_CHECK_EQUAL(std::get<0>(otherObjects).size(), 1);
- BOOST_CHECK_EQUAL(std::get<1>(otherObjects).size(), 4);
- BOOST_CHECK_EQUAL(std::get<2>(otherObjects).size(), 1);
+ BOOST_CHECK_EQUAL(size(), 5);
+ BOOST_CHECK_EQUAL(size<Multi>(), 1);
+ BOOST_CHECK_EQUAL(size<Sub>(), 4);
+ BOOST_CHECK_EQUAL(size<Base2>(), 1);
}
BOOST_AUTO_TEST_CASE(removeMulti)