diff --git a/map/multi_fixed.hpp b/map/multi_fixed.hpp index bb18302d..9393acfa 100644 --- a/map/multi_fixed.hpp +++ b/map/multi_fixed.hpp @@ -236,6 +236,19 @@ namespace cruft::map { m_store.data[m_size].~value_type (); } + template + void + erase_keys (IteratorT first, IteratorT last) + { + CHECK (std::is_sorted (first, last)); + + // HACK: This is hopelessly naive, but it works. + for (auto cursor = first; cursor != last; ++cursor) + if (auto pos = find (*cursor); pos != end ()) + erase (pos); + } + + std::size_t erase (key_type const&); bool empty (void) const { return m_size == 0; } diff --git a/test/map/multi_fixed.cpp b/test/map/multi_fixed.cpp index 0225fbe1..3f13bcc0 100644 --- a/test/map/multi_fixed.cpp +++ b/test/map/multi_fixed.cpp @@ -87,6 +87,15 @@ int main () tap.expect_eq (init, expected, "erase of last element"); } + { + cruft::map::multi_fixed<4, int, int> init {{ {0,0}, {1,1}, {2,2}, {3,3} }}; + static constexpr int keys[] = { 1, 3 }; + init.erase_keys (std::begin (keys), std::end (keys)); + cruft::map::multi_fixed<4, int, int> expected {{ {0,0}, {2,2} }}; + tap.expect_eq (init, expected, "erase_keys"); + } + + test_sorted_iterators (tap); test_bad_alloc (tap);