Home | Libraries | People | FAQ | More |
This section refers to element iteration over interval containers. Element iterators are available as associated types on interval sets and interval maps.
Variant |
Associated element iterator type for interval container |
---|---|
forward |
|
const forward |
|
reverse |
|
const reverse |
|
There are also associated iterators types T::iterator
,
T::const_iterator
, T::reverse_iterator
and T::reverse_const_iterator
on interval containers.
These are segment iterators.
Segment iterators are "first citizen iterators". Iteration over
segments is fast, compared to an iteration over elements, particularly if
intervals are large. But if we want to view our interval containers as containers
of elements that are usable with std::algoritms, we need to iterate over
elements.
Iteration over elements . . .
domain_types
On the other hand, sometimes iteration over interval containers on the element
level might be desired, if you have some interface that works for std::SortedAssociativeContainers
of elements and you need to quickly use it with an interval container. Accepting
the poorer performance might be less bothersome at times than adjusting your
whole interface for segment iteration.
Caution | |
---|---|
So we advice you to choose element iteration over interval containers judiciously. Do not use element iteration by default or habitual. Always try to achieve results using member functions, global functions or operators (preferably inplace versions) or iteration over segments first. |
Synopsis Complexities |
interval |
interval |
---|---|---|
|
O(1) |
O(1) |
|
O(1) |
O(1) |
|
O(1) |
O(1) |
|
O(1) |
O(1) |
Element iteration |
Description |
---|---|
element_iterator elements_begin(T&) element_const_iterator elements_begin(const T&)
|
Returns an element iterator to the first element of the container. |
element_iterator elements_end(T&) element_const_iterator elements_end(const T&)
|
Returns an element iterator to a position |
element_reverse_iterator elements_rbegin(T&) element_const_reverse_iterator elements_rbegin(const T&)
|
Returns a reverse element iterator to the last element of the container. |
element_reverse_iterator elements_rend(T&) element_const_reverse_iterator elements_rend(const T&)
|
Returns a reverse element iterator to a position |
Example
interval_set<int> inter_set; inter_set.add(interval<int>::right_open(0,3)) .add(interval<int>::right_open(7,9)); for(interval_set<int>::element_const_iterator creeper = elements_begin(inter_set); creeper != elements_end(inter_set); ++creeper) cout << *creeper << " "; cout << endl; //Program output: 0 1 2 7 8 for(interval_set<int>::element_reverse_iterator repeerc = elements_rbegin(inter_set); repeerc != elements_rend(inter_set); ++repeerc) cout << *repeerc << " "; cout << endl; //Program output: 8 7 2 1 0
See also . . .
Back to section . . .