The member function erase accepts const_iterator(s).
For example
iterator erase(const_iterator position);
In early Standards the function indeed was declared with non-constant iterators.
Take into account that the function returns a non-constant iterator but it can be converted implicitly to a constant iterator and can be compared with constant iterators.
By the way this call
g1.erase(i);
erases nothing because after the loop i
is equal to the iterator returned by the function cend
provided that the name i is defined before the loop.
auto i = g1.cbegin();
for (; i != g1.cend(); ++i){
cout << *i << " ";
}
//below code erases element at const pointer
g1.erase(i);
You can erase an element of the vector using the const_iterator because the vector itself is not constant. If the vector would be constant you could not erase its element.
That is the erase
member function changes the vector itself (so it may not be applied to a constant vector), but it does not change elements of the vector using the const_iterator.