diff --git a/src/gpgmm/utils/StableList.h b/src/gpgmm/utils/StableList.h index e346cbf1..8eae71cd 100644 --- a/src/gpgmm/utils/StableList.h +++ b/src/gpgmm/utils/StableList.h @@ -352,6 +352,10 @@ namespace gpgmm { return mIndex; } + StableListT* list() const { + return mList; + } + protected: StableListT* mList; size_t mIndex; @@ -379,11 +383,17 @@ namespace gpgmm { StableListIteratorBase>::operator++(); return *this; } + + iterator operator+(int offset) const { + iterator tmp = *this; + tmp.mIndex += offset; + return tmp; + } }; struct const_iterator : public StableListIteratorBase> { const_iterator(const iterator& it) - : StableListIteratorBase>(it.mList, it.mIndex) { + : StableListIteratorBase>(it.list(), it.index()) { } const_iterator(StableList const* list, size_t index) @@ -406,10 +416,16 @@ namespace gpgmm { StableListIteratorBase>::operator++(); return *this; } + + const_iterator operator+(int offset) const { + const_iterator tmp = *this; + tmp.mIndex += offset; + return tmp; + } }; void erase(const_iterator it) { - erase(it.mIndex); + erase(it.index()); } iterator begin() { diff --git a/src/tests/unittests/StableListTests.cpp b/src/tests/unittests/StableListTests.cpp index f2988111..8c610b7e 100644 --- a/src/tests/unittests/StableListTests.cpp +++ b/src/tests/unittests/StableListTests.cpp @@ -72,6 +72,17 @@ TEST(StableListTests, Insert) { EXPECT_EQ(list[2], 0); } +TEST(StableListTests, Get) { + StableList list; + list.push_back(0); + list.push_back(1); + list.push_back(2); + + EXPECT_EQ(*list.begin(), 0); + EXPECT_EQ(*list.begin() + 1, 1); + EXPECT_EQ(*list.begin() + 2, 2); +} + TEST(StableListTests, RemoveEnds) { StableList list; list.push_back(0);