util/IntrusiveForwardList: add method remove_and_dispose_if()
This commit is contained in:
parent
78d28063c4
commit
5b28a987e5
|
@ -199,6 +199,30 @@ public:
|
|||
last_cache = {};
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the number of removed items
|
||||
*/
|
||||
std::size_t remove_and_dispose_if(std::predicate<const_reference> auto pred,
|
||||
Disposer<value_type> auto dispose) noexcept {
|
||||
std::size_t result = 0;
|
||||
|
||||
for (auto prev = before_begin(), current = std::next(prev);
|
||||
current != end();) {
|
||||
auto &item = *current;
|
||||
|
||||
if (pred(item)) {
|
||||
++result;
|
||||
++current;
|
||||
erase_after(prev);
|
||||
dispose(&item);
|
||||
} else {
|
||||
prev = current++;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
const_reference front() const noexcept {
|
||||
return *Cast(head.next);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue