@@ -30,6 +30,7 @@ Revision History:
30
30
#include < functional>
31
31
#include < memory>
32
32
#include < type_traits>
33
+ #include < utility>
33
34
#include " util/memory_manager.h"
34
35
#include " util/hash.h"
35
36
#include " util/z3_exception.h"
@@ -558,7 +559,7 @@ class vector {
558
559
for (; pos != e; ++pos, ++prev) {
559
560
*prev = std::move (*pos);
560
561
}
561
- reinterpret_cast <SZ *>(m_data)[SIZE_IDX]-- ;
562
+ pop_back () ;
562
563
}
563
564
564
565
void erase (T const & elem) {
@@ -568,6 +569,20 @@ class vector {
568
569
}
569
570
}
570
571
572
+ /* * Erase all elements that satisfy the given predicate. Returns the number of erased elements. */
573
+ template <typename UnaryPredicate>
574
+ SZ erase_if (UnaryPredicate should_erase) {
575
+ iterator i = begin ();
576
+ iterator const e = end ();
577
+ for (iterator j = begin (); j != e; ++j)
578
+ if (!should_erase (std::as_const (*j)))
579
+ *(i++) = std::move (*j);
580
+ SZ const count = e - i;
581
+ SASSERT_EQ (i - begin (), size () - count);
582
+ shrink (size () - count);
583
+ return count;
584
+ }
585
+
571
586
void shrink (SZ s) {
572
587
if (m_data) {
573
588
SASSERT (s <= reinterpret_cast <SZ *>(m_data)[SIZE_IDX]);
@@ -756,7 +771,8 @@ using bool_vector = svector<bool>;
756
771
757
772
template <typename T>
758
773
inline std::ostream& operator <<(std::ostream& out, svector<T> const & v) {
759
- for (unsigned u : v) out << u << " " ;
774
+ for (auto const & x : v)
775
+ out << x << " " ;
760
776
return out;
761
777
}
762
778
0 commit comments