Iterator definitions
In C++, 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 (at least, the increment (++) 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 forms of iterators exist. For example, each container type (such as a vector)
has a specific iterator type designed to iterate through its elements in an efficient way.
Notice that while a pointer is a form of iterator, not all iterators have the same functionality a pointer has; To distinguish
between the requirements an iterator shall have for a specific algorithm, five different iterator categories exist:
In this graph, each iterator category implements the functionalities of all categories to its right:
Input and output iterators are the most limited types of iterators, specialized in performing only sequential input or
ouput operations.
Forward iterators have all the functionality of input and output iterators, although they are limited to one direction
in which to iterate through a range.
Bidirectional iterators can be iterated through in both directions. All standard containers support at least bidirectional
iterators types.
Random access iterators implement all the functionalities of bidirectional iterators, plus, they have the ability to
access ranges non-sequentially: offsets can be directly applied to these iterators without iterating through all
the elements in between. This provides these iterators with the same functionality as standard pointers
(pointers are iterators of this category).
The characteristics of each category of iterators 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.
Random access iterators have all caracteristics. Bidirectional iterators have a subset of random access iterators's.
Forward iterators have a subset of bidirectional iterators's. And input and output have each their own subset
of forward iterator's.
Inserters:
Inserter iterators
Input/Output iterators
has the ability to iterate through the elements of that range using a set of operators (at least, the increment (++) 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 forms of iterators exist. For example, each container type (such as a vector)
has a specific iterator type designed to iterate through its elements in an efficient way.
Notice that while a pointer is a form of iterator, not all iterators have the same functionality a pointer has; To distinguish
between the requirements an iterator shall have for a specific algorithm, five different iterator categories exist:
Iterator categories
Iterators are classified in five categories depending on the functionality they implement:![]() |
![]() |
![]() |
||||
![]() |
In this graph, each iterator category implements the functionalities of all categories to its right:
Input and output iterators are the most limited types of iterators, specialized in performing only sequential input or
ouput operations.
Forward iterators have all the functionality of input and output iterators, although they are limited to one direction
in which to iterate through a range.
Bidirectional iterators can be iterated through in both directions. All standard containers support at least bidirectional
iterators types.
Random access iterators implement all the functionalities of bidirectional iterators, plus, they have the ability to
access ranges non-sequentially: offsets can be directly applied to these iterators without iterating through all
the elements in between. This provides these iterators with the same functionality as standard pointers
(pointers are iterators of this category).
The characteristics of each category of iterators 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.
Random access iterators have all caracteristics. Bidirectional iterators have a subset of random access iterators's.
Forward iterators have a subset of bidirectional iterators's. And input and output have each their own subset
of forward iterator's.
Base
iterator | Iterator base class (class template) |
iterator_traits | Iterator traits (class template) |
Functions
Iterator operations:advance | Advance iterator (function template) |
distance | Return distance between iterators (function template) |
Inserters:
back_inserter | Construct a back insert iterator (function template) |
front_inserter | Constructs a front insert iterator (function template) |
inserter | Construct an insert iterator (function template) |
Predefined iterators
reverse_iterator | Reverse iterator (class template) |
Inserter iterators
back_insert_iterator | Back insert iterator (class template) |
front_insert_iterator | Front insert iterator (class template) |
insert_iterator | Insert iterator (class template) |
Input/Output iterators
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) |
'자료구조 및 알고리즘' 카테고리의 다른 글
P,NP (0) | 2010.01.03 |
---|---|
(STL) set , map 등에서는 const_iterator만 써야 한다. (0) | 2009.11.23 |
임의의 시퀀스를 만들 때. (0) | 2009.10.12 |
GA design feedback (0) | 2009.10.06 |
UVA 로봇 심사위원에게 Accepted 사인 받기 위한 점검. (0) | 2009.07.10 |