How do I acquire a const_iterator (of some container class) from an iterator (of that container class) in C++? What about a const_iterator from an insert_iterator? The resulting iterator should point at the same spot as the original does.
C++ iterator to const_iterator
24.3k Views Asked by Thomas Eding At
2
Containers are required to provide
iteratoras a type convertible toconst_iterator, so you can convert implicitly:std::insert_iterators are output iterators. This gives no way to convert them to a regularContainer::iteratorwhich must be a forward iterator.Another kind of insert iterator may allow such a thing, but those obtained from the standard functions don't.
I guess you can write your own wrapper around
std::insert_iteratorthat exposes the protected memberiter, though: