The Semantics of const_iterator

A recent subscriber of one of the C++ newsgroups posted the following question:Why did the C++ standardization committee created a const_iterator instead of a const iterator? Or, at least, why not require const_iterator to actually have type const iterator? The answer is simple: a const_iterator is nota const iterator. This means that you can alter the value of a const_iterator, e.g., increment it using ++. However, you cannot change the element to which a const_iterator points. In other words, if you think of an iterator as a pointer to T, a const_iterator is not a const pointer to T, but rather, it

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

Recent Articles: