CARVIEW |
Select Language
HTTP/1.1 200 OK
Server: nginx
Date: Sun, 20 Jul 2025 13:17:41 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
ETag: W/"8eee-jzRSB3tmDHexKOfspQ1w0F5Vp8A"
Content-Encoding: gzip
An iterator is any object that, pointing to some element in a range of elements (such as an array or a container), has the ability to iterate through the elements of that range using a set of operators (with at least the increment (
The most obvious form of iterator is a pointer: A pointer can point to elements in an array, and can iterate through them using the increment operator (
Notice that while a pointer is a form of iterator, not all iterators have the same functionality of pointers; Depending on the properties supported by iterators, they are classified into five different categories:
Input and output iterators are the most limited types of iterators: they can perform sequential single-pass input or output operations.
Forward iterators have all the functionality of input iterators and -if they are not constant iterators- also the functionality of output iterators, although they are limited to one direction in which to iterate through a range (forward). All standard containers support at least forward iterator types.
Bidirectional iterators are like forward iterators but can also be iterated through backwards.
Random-access iterators implement all the functionality of bidirectional iterators, and also have the ability to access ranges non-sequentially: distant elements can be accessed directly by applying an offset value to an iterator without iterating through all the elements in between. These iterators have a similar functionality to standard pointers (pointers are iterators of this category).
The properties of each iterator category are:
Where X is an iterator type, a and b are objects of this iterator type, t is an object of the type pointed by the iterator type, and n is an integer value.
For more details, see the references for input iterator, output iterator, forward iterator, bidirectional iterator and random-access iterator.
Iterator generators:
Reference
C library:
- <cassert> (assert.h)
- <cctype> (ctype.h)
- <cerrno> (errno.h)
-
<cfenv> (fenv.h)C++11
- <cfloat> (float.h)
-
<cinttypes> (inttypes.h)C++11
- <ciso646> (iso646.h)
- <climits> (limits.h)
- <clocale> (locale.h)
- <cmath> (math.h)
- <csetjmp> (setjmp.h)
- <csignal> (signal.h)
- <cstdarg> (stdarg.h)
-
<cstdbool> (stdbool.h)C++11
- <cstddef> (stddef.h)
-
<cstdint> (stdint.h)C++11
- <cstdio> (stdio.h)
- <cstdlib> (stdlib.h)
- <cstring> (string.h)
-
<ctgmath> (tgmath.h)C++11
- <ctime> (time.h)
-
<cuchar> (uchar.h)C++11
- <cwchar> (wchar.h)
- <cwctype> (wctype.h)
Containers:
-
<array>C++11
- <deque>
-
<forward_list>C++11
- <list>
- <map>
- <queue>
- <set>
- <stack>
-
<unordered_map>C++11
-
<unordered_set>C++11
- <vector>
-
Input/Output:
Multi-threading:
-
<atomic>C++11
-
<condition_variable>C++11
-
<future>C++11
-
<mutex>C++11
-
<thread>C++11
-
Other:
- <algorithm>
- <bitset>
-
<chrono>C++11
-
<codecvt>C++11
- <complex>
- <exception>
- <functional>
-
<initializer_list>C++11
- <iterator>
- <limits>
- <locale>
- <memory>
- <new>
- <numeric>
-
<random>C++11
-
<ratio>C++11
-
<regex>C++11
- <stdexcept>
- <string>
-
<system_error>C++11
-
<tuple>C++11
-
<type_traits>C++11
-
<typeindex>C++11
- <typeinfo>
- <utility>
- <valarray>
<iterator>
- iterator
- iterator_traits
functions
- advance
- back_inserter
-
beginC++11
- distance
-
endC++11
- front_inserter
- inserter
-
make_move_iteratorC++11
-
nextC++11
-
prevC++11
iterator categories
predefined iterators
- Reference
- <iterator>
header
<iterator>
Iterator definitions
++
) and dereference (*
) operators).The most obvious form of iterator is a pointer: A pointer can point to elements in an array, and can iterate through them using the increment operator (
++
). But other kinds of iterators are possible. For example, each container type (such as a list) has a specific iterator type designed to iterate through its elements.Notice that while a pointer is a form of iterator, not all iterators have the same functionality of pointers; Depending on the properties supported by iterators, they are classified into five different categories:
Iterator categories
Iterators are classified into five categories depending on the functionality they implement:Input and output iterators are the most limited types of iterators: they can perform sequential single-pass input or output operations.
Forward iterators have all the functionality of input iterators and -if they are not constant iterators- also the functionality of output iterators, although they are limited to one direction in which to iterate through a range (forward). All standard containers support at least forward iterator types.
Bidirectional iterators are like forward iterators but can also be iterated through backwards.
Random-access iterators implement all the functionality of bidirectional iterators, and also have the ability to access ranges non-sequentially: distant elements can be accessed directly by applying an offset value to an iterator without iterating through all the elements in between. These iterators have a similar functionality to standard pointers (pointers are iterators of this category).
The properties of each iterator category are:
category | properties | valid expressions | |||
---|---|---|---|---|---|
all categories | copy-constructible, copy-assignable and destructible | X b(a); | |||
Can be incremented | ++a | ||||
Random Access | Bidirectional | Forward | Input | Supports equality/inequality comparisons | a == b |
Can be dereferenced as an rvalue | *a a->m | ||||
Output | Can be dereferenced as an lvalue (only for mutable iterator types) | *a = t *a++ = t | |||
default-constructible | X a; X() | ||||
Multi-pass: neither dereferencing nor incrementing affects dereferenceability | { b=a; *a++; *b; } | ||||
Can be decremented | --a a-- *a-- | ||||
Supports arithmetic operators + and - | a + n n + a a - n a - b | ||||
Supports inequality comparisons (<, >, <= and >=) between iterators | a < b a > b a <= b a >= b | ||||
Supports compound assignment operations += and -= | a += n a -= n | ||||
Supports offset dereference operator ([]) | a[n] |
Where X is an iterator type, a and b are objects of this iterator type, t is an object of the type pointed by the iterator type, and n is an integer value.
For more details, see the references for input iterator, output iterator, forward iterator, bidirectional iterator and random-access iterator.
Functions
Iterator operations:- advance
- Advance iterator (function template)
- distance
- Return distance between iterators (function template)
- begin
- Iterator to beginning (function template)
- end
- Iterator to end (function template)
- prev
- Get iterator to previous element (function template)
- next
- Get iterator to next element (function template)
Iterator generators:
- back_inserter
- Construct back insert iterator (function template)
- front_inserter
- Constructs front insert iterator (function template)
- inserter
- Construct insert iterator (function template)
- make_move_iterator
- Construct move iterator (function template)
Classes
- iterator
- Iterator base class (class template)
- iterator_traits
- Iterator traits (class template)
Predefined iterators
- reverse_iterator
- Reverse iterator (class template)
- move_iterator
- Move iterator (class template)
- back_insert_iterator
- Back insert iterator (class template)
- front_insert_iterator
- Front insert iterator (class template)
- insert_iterator
- Insert iterator (class template)
- istream_iterator
- Istream iterator (class template)
- ostream_iterator
- Ostream iterator (class template)
- istreambuf_iterator
- Input stream buffer iterator (class template)
- ostreambuf_iterator
- Output stream buffer iterator (class template)
Category tags
- input_iterator_tag
- Input iterator category (class)
- output_iterator_tag
- Output iterator category (class)
- forward_iterator_tag
- Forward iterator category (class)
- bidirectional_iterator_tag
- Bidirectional iterator category (class)
- random_access_iterator_tag
- Random-access iterator category (class)
Home page | Privacy policy
© cplusplus.com, 2000-2025 - All rights reserved - v3.3.4s
Spotted an error? contact us
© cplusplus.com, 2000-2025 - All rights reserved - v3.3.4s
Spotted an error? contact us