Site icon Learn C++

Introduction to C++ Iterators

Iterator abstracts the concept of pointer to the sequence in range [begin, end), and thus provides the following basic operations:

Iterator to the element of the sequence in range [begin, end) is valid from the moment of initialization and until:

Please note, that the sequence range of [begin, end) is half-opened, since the end is serves as the element one-past-the-last element of the sequence. An attempt of reading or writing by using the end may lead to the undefined behavior of the program, and therefore illegal. Iterator that points to the end is primarily used to determine the end of sequence by using the comparison operator !=. Also, the end is conventionally used by functions as the return value to indicate the search failure (i.e. “the requested element not found” condition), for example:

[crayon-6741c1a0ad4ae101696267/]
Exit mobile version