diff --git a/Map.hpp b/Map.hpp index 476a917..b82f0e2 100644 --- a/Map.hpp +++ b/Map.hpp @@ -36,6 +36,7 @@ template struct BookKeeping { friend class Map; Map &container; ValueType value; + typename std::vector::iterator self; Color color; // nullptr indicates empty Self *parent; @@ -559,7 +560,10 @@ private: public: // TODO: check that the way of reconnecting next and prev works + // TODO: need to revalidate void erase(Iterator pos) { + auto revalidate_begin = pos.ref->container.begin() - pos.ref->self; + auto &container = pos.ref->container; // simple cases Node *ref = pos.ref; // 2 children @@ -604,6 +608,11 @@ public: else { this->complex_erase(pos); } + // need to revalidate iterators now so future erasures aren't fucked + for (auto iter = container.begin() + revalidate_begin; + iter != container.end(); ++iter) { + iter->self = iter; + } } void erase(const Key_T &key) { this->erase(this->find(key)); } void clear() {