Iterators
Method |
---|
MultimapContainer |
Get constant iterators |
const_iterator begin() const noexcept; |
const_iterator end() const noexcept; |
const_iterator cbegin() const noexcept; |
const_iterator cend() const noexcept; |
Get iterators |
iterator begin() noexcept; |
iterator end() noexcept; |
Get reverse iterators |
std::reverse_iterator<const_iterator> rbegin() const noexcept; |
std::reverse_iterator<const_iterator> rend() const noexcept; |
std::reverse_iterator<iterator> rbegin() noexcept ; |
std::reverse_iterator<iterator> rend() noexcept; |
Get constant reverse iterators |
std::reverse_iterator<const_iterator> crbegin() const noexcept; |
std::reverse_iterator<const_iterator> crend() const noexcept; |
Return value
begin()
- Iterator to the first element in the containerend()
- Iterator to the past-the-end element in the container (see notes)
Complexity
Notes
At each iteration, these iterators report the next tree element in a depth-first search algorithm. The reverse iterators perform a reversed depth-first search algorithm, where we get the next element at the rightmost element of the left sibling node or return the parent node when there are no more siblings.
Info
All spatial maps have two kinds of iterators: the usual iterators and query iterators. Query iterators contain a list of predicates and skip all elements that do not match these predicates. The functions in this section describe only the usual iterators.
Query iterators and normal iterators compare equal when they point to the same element, but this doesn't mean their next element is the same element.
Python Iterators
The Python interface uses ranges instead of single iterators. The begin
and end
functions are not directly exposed.
Note for C++ Beginners
The iterators begin()
point to the first element in the container. The iterators end()
point to one position after the last element in the container.
This means that, given an iterator it
initially equivalent to begin()
, we can iterate elements while (it != end()) { ++it; }
. If the spatial_map
is empty, begin()
returns an iterator equal to end()
.
The functions beginning with c
return constant iterators. When we dereference a constant iterators with operator*
, they only return references to constant values (const value_type&
).
The functions beginning with r
return reverse iterators. Reverse iterators go from the last to the first element.
Example of reverse iterators
The functions beginning with cr
return constant reverse iterators.
!!! note "Intermediate C++**
Like all other associative containers, non-const iterators return references to std::pair<const key_type, mapped_type>
and not std::pair<key_type, mapped_type>
like one might think. This is meant to protect the associative relationship between nodes in the container.
Example
Continuing from the previous example:
1 2 3 4 5 6 7 8 9 |
|
1 2 3 4 5 6 7 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
|