The following example will not compile using g++ 4.8.2:
#include
#include
using namespace std;
int main() {
vector
This is a known bug in gcc: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57158
erase requires an iterator instead of a const_iterator with current gcc's.
You can get a non-const iterator via pointer arithmetic, here's a helper function to do that:
template<typename T>
typename std::vector<T>::iterator
const_iterator_cast(std::vector<T>& v, typename std::vector<T>::const_iterator iter)
{
return v.begin() + (iter - v.cbegin());
}
used like so:
std::vector<T> v(1);
auto citer = v.cbegin();
v.erase( const_iterator_cast(v, citer) );