I’ve implemented a class that wraps std::vector
and offers some extra functionality for my needs.
It looks like this (Only relevant members are included):
#include <vector>
#include <algorithm>
class my_vector {
private:
std::vector<int*> m_arr;
public:
using iterator_t = decltype(m_arr)::iterator;
void del(iterator_t left, iterator_t right) {
std::for_each(left, right, [](int* elem) { delete elem; });
m_arr.erase(left, right);
}
void del_all() {
del(m_arr.begin(), m_arr.end())
}
~my_vector() {
del_all();
}
};
When testing, I’ve stumbled upon the “vector erase iterator outside range” error. After some attempts I managed to catch it in debugger and looking through the call stack confused me.
In my current call stack m_arr.size()
equals to 1 and del
is called by del_all
by the destructor. The error occurs at the m_arr.erase(left, right);
line. I have made sure that left
in del
equals to m_arr.begin()
.
Now, why does it tell me that the iterator is out of range when trying to erase the only element of the vector?
In the error breakpoint in the STL erase
function _First.ptr
ends with a710 and _Last.ptr
ends with a718
I genuinely cannot decipher that _STL_VERIFY line