mirror of
https://github.com/Z3Prover/z3
synced 2025-04-23 17:15:31 +00:00
Add vector::erase_if
(ended up unused but I didn't want to throw it away)
This commit is contained in:
parent
e0db58c998
commit
1ef01c5042
1 changed files with 15 additions and 0 deletions
|
@ -556,6 +556,7 @@ public:
|
|||
*prev = std::move(*pos);
|
||||
}
|
||||
reinterpret_cast<SZ *>(m_data)[SIZE_IDX]--;
|
||||
// TODO: where is the destructor called?
|
||||
}
|
||||
|
||||
void erase(T const & elem) {
|
||||
|
@ -565,6 +566,20 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
/** Erase all elements that satisfy the given predicate. Returns the number of erased elements. */
|
||||
template <typename UnaryPredicate>
|
||||
SZ erase_if(UnaryPredicate should_erase) {
|
||||
iterator i = begin();
|
||||
iterator const e = end();
|
||||
for (iterator j = begin(); j != e; ++j)
|
||||
if (!should_erase(std::as_const(*j)))
|
||||
*(i++) = std::move(*j);
|
||||
SZ const count = e - i;
|
||||
SASSERT_EQ(i - begin(), size() - count);
|
||||
shrink(size() - count);
|
||||
return count;
|
||||
}
|
||||
|
||||
void shrink(SZ s) {
|
||||
if (m_data) {
|
||||
SASSERT(s <= reinterpret_cast<SZ *>(m_data)[SIZE_IDX]);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue