util/IntrusiveList: remove_and_dispose_if() returns the number of removed items

This commit is contained in:
Max Kellermann 2022-12-01 18:40:44 +01:00 committed by Max Kellermann
parent c65b1fee8d
commit 7475e971bc

View File

@ -296,8 +296,13 @@ public:
} }
} }
void remove_and_dispose_if(Predicate<const_reference> auto pred, /**
Disposer<value_type> auto dispose) noexcept { * @return the number of removed items
*/
std::size_t remove_and_dispose_if(Predicate<const_reference> auto pred,
Disposer<value_type> auto dispose) noexcept {
std::size_t result = 0;
auto *n = head.next; auto *n = head.next;
while (n != &head) { while (n != &head) {
@ -308,8 +313,11 @@ public:
ToHook(*i).unlink(); ToHook(*i).unlink();
--counter; --counter;
dispose(i); dispose(i);
++result;
} }
} }
return result;
} }
const_reference front() const noexcept { const_reference front() const noexcept {