C++C++11C++14C++17Generic ProgrammingIteratorsLearn C++

Helpers for Generic C++ Code Iterating Over Sequences

The iterator library that is part of the C++ Standard Library provides the following helpers for writing generic code:

All the functions above are defined in the <iterator> header. It’s always preferable to use these generic functions when writing the generic code instead of using equivalent member functions of the containers.

Functions from (1) to (8) are defined for built-in arrays and for every type that provides members begin() and end(). Note, that std::cbegin() requires the definition of the constant version of member function c.begin().

Functions for (9) to (12): std::prev() and std::next() are generic functions to increment or decrement the iterator by the specified number of hops (by default, 1), function std::distance() is a generic function to calculate the number of hops between the specified pair of iterators and function std::advance() is a generic equivalent of the operator +=.

Please note, if either the argument of std::next() and std::advance() is negative or the argument of std::prev() is positive then the specified iterator must be bidirectional iterator (see Categories of Iterators in C++).

close

Oh hi there 👋
It’s nice to meet you.

Sign up to receive awesome C++ content in your inbox, every day.

We don’t spam! Read our privacy policy for more info.


Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial

Free C++Builder Community Edition

Related posts
C++ComponentsLanguage FeatureLearn C++

How To Add Shadow Effects To Your C++ Apps

C++ComponentsLanguage FeatureLearn C++

How To Make Controls Have A Glow Effect In C++?

C++Learn C++

What Is The sscanf Function In C++ And How Can I Use It?

C++C++17Introduction to C++Language FeatureLearn C++

This Is How To Use Parallel Programming in C++ Builder

jaJapanese