From 7475e971bc4271351966c645eee51e385a3b4915 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 1 Dec 2022 18:40:44 +0100 Subject: [PATCH] util/IntrusiveList: remove_and_dispose_if() returns the number of removed items --- src/util/IntrusiveList.hxx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/util/IntrusiveList.hxx b/src/util/IntrusiveList.hxx index 183e98c93..7d0a5f310 100644 --- a/src/util/IntrusiveList.hxx +++ b/src/util/IntrusiveList.hxx @@ -296,8 +296,13 @@ public: } } - void remove_and_dispose_if(Predicate auto pred, - Disposer auto dispose) noexcept { + /** + * @return the number of removed items + */ + std::size_t remove_and_dispose_if(Predicate auto pred, + Disposer auto dispose) noexcept { + std::size_t result = 0; + auto *n = head.next; while (n != &head) { @@ -308,8 +313,11 @@ public: ToHook(*i).unlink(); --counter; dispose(i); + ++result; } } + + return result; } const_reference front() const noexcept {