From 512c6bff0e8162cdc9760e57551c3ff4b552f28b Mon Sep 17 00:00:00 2001 From: Christopher Lam Date: Sat, 19 Aug 2023 08:31:01 +0800 Subject: [PATCH] maybe size() too --- gnucash/gnome-utils/gnc-tree-container.hpp | 8 ++++++++ gnucash/gnome-utils/test/test-tree-container.cpp | 1 + 2 files changed, 9 insertions(+) diff --git a/gnucash/gnome-utils/gnc-tree-container.hpp b/gnucash/gnome-utils/gnc-tree-container.hpp index ab9d40804fb..a2f943589ce 100644 --- a/gnucash/gnome-utils/gnc-tree-container.hpp +++ b/gnucash/gnome-utils/gnc-tree-container.hpp @@ -156,6 +156,14 @@ class GncTreeContainer return TreeModelIterator(m_model, iter); }; + size_t size() + { + int i = 0; + for (auto n = begin(); n.has_value(); ++n) + i++; + return i; + }; + bool empty() { return begin() == end(); }; private: diff --git a/gnucash/gnome-utils/test/test-tree-container.cpp b/gnucash/gnome-utils/test/test-tree-container.cpp index 83855088b09..72b643ce6a0 100644 --- a/gnucash/gnome-utils/test/test-tree-container.cpp +++ b/gnucash/gnome-utils/test/test-tree-container.cpp @@ -58,6 +58,7 @@ TEST(GncTreeContainer, Basic) { // test non-empty EXPECT_EQ(false, container.empty()); + EXPECT_EQ(10, container.size()); { auto is_five = [](auto it){ return it.template get_int(COLUMN_INT) == 5; };