Reference documentation for deal.II version 9.2.0
|
#include <deal.II/base/iterator_range.h>
Public Types | |
using | IteratorOverIterators = ::IteratorOverIterators< Iterator > |
using | iterator = Iterator |
Public Member Functions | |
IteratorRange () | |
IteratorRange (const iterator begin, const iterator end) | |
IteratorOverIterators | begin () |
IteratorOverIterators | begin () const |
IteratorOverIterators | end () const |
IteratorOverIterators | end () |
Private Attributes | |
const IteratorOverIterators | it_begin |
const IteratorOverIterators | it_end |
A class that is used to denote a collection of iterators that can be expressed in terms of a range of iterators characterized by a begin and an end iterator. As is common in C++, these ranges are specified as half open intervals defined by a begin iterator and a one-past-the-end iterator.
The purpose of this class is so that classes such as Triangulation and DoFHandler can return ranges of cell iterators using an object of the current type from functions such as Triangulation::cell_iterators() and that such an object can then be used in a range-based for loop as supported by C++11, see also C++11 standard.
For example, such a loop could look like this if the goal is to set the user flag on every active cell:
In other words, the cell
objects are iterators, and the range object returned by Triangulation::active_cell_iterators() and similar functions are conceptually thought of as collections of iterators.
Of course, the class may also be used to denote other iterator ranges using different kinds of iterators into other containers.
Informally, the way the C++11 standard describes range- based for loops works as follows: A range-based for loop of the form
where c
is a container or collection, is equivalent to the following loop:
(The precise definition can be found here: https://en.cppreference.com/w/cpp/language/range-for .) In other words, the compiler introduces a temporary variable that iterates over the elements of the container or collection, and the original variable v
that appeared in the range-based for loop represents the dereferenced state of these iterators – namely, the elements of the collection.
In the context of loops over cells, we typically want to retain the fact that the loop variable is an iterator, not a value. This is because in deal.II, we never actually use the dereferenced state of a cell iterator: conceptually, it would represent a cell, and technically it is implemented by classes such as CellAccessor and DoFCellAccessor, but these classes are never used explicitly. Consequently, what we would like is that a call such as Triangulation::active_cell_iterators() returns an object that represents a collection of iterators of the kind {begin, begin+1, ..., end-1}
. This is conveniently expressed as the half open interval [begin,end)
. The loop variable in the range- based for loop would then take on each of these iterators in turn.
To represent the desired semantics as outlined above, this class stores a half-open range of iterators [b,e)
of the given template type. Secondly, the class needs to provide begin() and end() functions in such a way that if you dereference the result of IteratorRange::begin(), you get the b
iterator. Furthermore, you must be able to increment the object returned by IteratorRange::begin() so that *(++begin()) == b+1
. In other words, IteratorRange::begin() must return an iterator that when dereferenced returns an iterator of the template type Iterator
: It is an iterator over iterators in the same sense as if you had a pointer into an array of pointers.
This is implemented in the form of the IteratorRange::IteratorOverIterators class.
Definition at line 129 of file iterator_range.h.
using IteratorRange< Iterator >::IteratorOverIterators = ::IteratorOverIterators<Iterator> |
Typedef for the iterator type that iterates over other iterators.
Definition at line 135 of file iterator_range.h.
using IteratorRange< Iterator >::iterator = Iterator |
Typedef for the iterator type represent by this class.
Definition at line 141 of file iterator_range.h.
|
inline |
Default constructor. Create a range represented by two default constructed iterators. This range is likely (depending on the type of the iterators) empty.
Definition at line 373 of file iterator_range.h.
|
inline |
Constructor. Constructs a range given the begin and end iterators.
[in] | begin | An iterator pointing to the first element of the range |
[in] | end | An iterator pointing past the last element represented by this range. |
Definition at line 381 of file iterator_range.h.
|
inline |
Return the iterator pointing to the first element of this range.
Definition at line 390 of file iterator_range.h.
IteratorOverIterators IteratorRange< Iterator >::begin | ( | ) | const |
Return the iterator pointing to the first element of this range.
|
inline |
Return the iterator pointing to the element past the last element of this range.
Definition at line 406 of file iterator_range.h.
IteratorOverIterators IteratorRange< Iterator >::end | ( | ) |
Return the iterator pointing to the element past the last element of this range.
|
private |
Iterators characterizing the begin and end of the range.
Definition at line 189 of file iterator_range.h.
|
private |
Definition at line 190 of file iterator_range.h.