const_cast
is used to remove const-ness of a variable. That is if you have const A& a
you can write A& b = const_cast<A&>(a)
. Now you will be able to modify b
or call non-const methods on it.
In this case you construct a const_iterator
from a regular iterator
and this is always possible even without using a const_cast
. Keep in mind these are two different types and simply const_iterator
happened to be constructable from iterator
C++ const-ness does not have much to do in this case.