
- C++ Library - Home
- C++ Library - <fstream>
- C++ Library - <iomanip>
- C++ Library - <ios>
- C++ Library - <iosfwd>
- C++ Library - <iostream>
- C++ Library - <istream>
- C++ Library - <ostream>
- C++ Library - <sstream>
- C++ Library - <streambuf>
- C++ Library - <atomic>
- C++ Library - <complex>
- C++ Library - <exception>
- C++ Library - <functional>
- C++ Library - <limits>
- C++ Library - <locale>
- C++ Library - <memory>
- C++ Library - <new>
- C++ Library - <numeric>
- C++ Library - <regex>
- C++ Library - <stdexcept>
- C++ Library - <string>
- C++ Library - <thread>
- C++ Library - <tuple>
- C++ Library - <typeinfo>
- C++ Library - <utility>
- C++ Library - <valarray>
- The C++ STL Library
- C++ Library - <array>
- C++ Library - <bitset>
- C++ Library - <deque>
- C++ Library - <forward_list>
- C++ Library - <list>
- C++ Library - <map>
- C++ Library - <multimap>
- C++ Library - <queue>
- C++ Library - <priority_queue>
- C++ Library - <set>
- C++ Library - <stack>
- C++ Library - <unordered_map>
- C++ Library - <unordered_set>
- C++ Library - <vector>
- C++ Library - <algorithm>
- C++ Library - <iterator>
- The C++ Advanced Library
- C++ Library - <any>
- C++ Library - <barrier>
- C++ Library - <bit>
- C++ Library - <chrono>
- C++ Library - <cinttypes>
- C++ Library - <clocale>
- C++ Library - <condition_variable>
- C++ Library - <coroutine>
- C++ Library - <cstdlib>
- C++ Library - <cstring>
- C++ Library - <cuchar>
- C++ Library - <charconv>
- C++ Library - <cfenv>
- C++ Library - <cmath>
- C++ Library - <ccomplex>
- C++ Library - <expected>
- C++ Library - <format>
- C++ Library - <future>
- C++ Library - <flat_set>
- C++ Library - <flat_map>
- C++ Library - <filesystem>
- C++ Library - <generator>
- C++ Library - <initializer_list>
- C++ Library - <latch>
- C++ Library - <memory_resource>
- C++ Library - <mutex>
- C++ Library - <mdspan>
- C++ Library - <optional>
- C++ Library - <print>
- C++ Library - <ratio>
- C++ Library - <scoped_allocator>
- C++ Library - <semaphore>
- C++ Library - <source_location>
- C++ Library - <span>
- C++ Library - <spanstream>
- C++ Library - <stacktrace>
- C++ Library - <stop_token>
- C++ Library - <syncstream>
- C++ Library - <system_error>
- C++ Library - <string_view>
- C++ Library - <stdatomic>
- C++ Library - <variant>
- C++ STL Library Cheat Sheet
- C++ STL - Cheat Sheet
- C++ Programming Resources
- C++ Programming Tutorial
- C++ Useful Resources
- C++ Discussion
C++ Library - <iterator>
Introduction
It is a pointer-like object that can be incremented with ++, dereferenced with *, and compared against another iterator with !=
Categories
category | properties | valid expressions | |||
---|---|---|---|---|---|
all categories | copy-constructible, copy-assignable and destructible |
b = a; | |||
It can be incremented |
a++ | ||||
Random Access | Bidirectional | Forward | Input | It supports equality/inequality comparisons |
a != b |
It can be dereferenced as an rvalue | *a a->m | ||||
Output | It 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; } | ||||
It can be decremented | --a a-- *a-- | ||||
It supports arithmetic operators + and - | a + n n + a a - n a - b | ||||
It supports inequality comparisons ( <, >, <= and >=) between iterators | a < b a > b a <= b a >= b | ||||
It supports compound assignment operations += and -= | a += n a -= n | ||||
It supports offset dereference operator ([]) | a[n] |
Functions
Sr.No. | Functions & Description |
---|---|
1 | advance It advances the iterator it by n element positions. |
2 | distance It returns distance between iterators. |
3 | begin It is used to begin an iterator. |
4 | end It is used to end an iterator. |
5 | prev It is used to get iterator to previous element. |
6 | next It is used to get iterator to next element. |
Iterator generators
Sr.No. | Iterator generators & Description |
---|---|
1 | back_inserter It constructs back insert iterator. |
2 | inserter It constructs insert iterator |
3 | make_move_iterator It construct move iterators. |
Classes
Sr.No. | Classes & Description |
---|---|
1 | iterator It iterators base class. |
2 | iterator_traits It is an iterator traits. |
Predefined iterators
Sr.No. | Predefined iterators & Description |
---|---|
1 | reverse_iterator It is a reverse iterator. |
2 | move_iterator It is a move iterator. |
3 | back_insert_iterator It is a back insert iterator. |
4 | front_insert_iterator It is a front insert iterator. |
5 | insert_iterator It is used to insert an iterator. |
6 | istream_iterator It is an input stream iterator. |
7 | ostream_iterator It is an output stream iterator. |
8 | istreambuf_iterator It is an input stream buffer iterator. |
7 | ostreambuf_iterator It is an output stream buffer iterator. |
Category tags
Sr.No. | Category tags & Description |
---|---|
1 | input_iterator_tag Input iterator category. |
2 | output_iterator_tag output iterator category. |
3 | forward_iterator_tag Forward iterator category. |
4 | bidirectional_iterator_tag Bidirectional iterator category. |
5 | random_access_iterator_tag Random-access iterator category. |