Spatial C++ Library
Generic Multi-Dimensional Containers and Spatial Operations
Iterators and Queries

Iterators are used in Spatial to perform all types of query in the container that can return a range of elements.

They are different categories of iterators with some specializations. When you do a query with an iterator, you simply iterate from begin() to end(). You have the possibility to stop in the middle of the iteration: iterators give great control over the queries that can be performed in each containers.

Overview

The table below provides an overview of all iterator types provided in the library. Containers are represented at the type T:

Iterator TypeDescription
T::iterator
T::const_iterator
The container's iterators, with T a container. They are used to list the contents of the container or identify an element in the container. The content of the container will be listed in no particular order: if 2 containers contain the same elements, iterating through both containers with this iterator is unlikely to return elements in the same sequence for both containers.
spatial::ordered_iterator<T>
spatial::ordered_iterator<const T>
This iterator will list all element of the container in a definite, predictable order: if 2 containers contains the same elements, iterating both containers with this iterator will return elements in the same sequence for both containers.
spatial::equal_iterator<T>
spatial::equal_iterator<const T>
When constructing this iterator, you need to specify a target value. This iterator will return all elements in the container that compare equally to the specified target value.
spatial::mapping_iterator<T>
spatial::mapping_iterator<const T>
When constructing this iterator, you specify a dimension of iteration. This iterator will return all elements in the container ordered along the dimension being specified. This iterator effectively "maps" all elements in the container on a single dimension.
spatial::region_iterator<T, P>
spatial::region_iterator<const T, P>
Here P represents a type that is a model of Region Predicate. This iterator is the tool that allows you to perform orthogonal range search: it returns all elements that are within the axis-aligned boundaries defined by P. Note that it does not return the elements in a particular order.
spatial::region_iterator<T>
spatial::region_iterator<const T>
In this form, the iterator above requires 2 values when constructed called low and high. It will return all elements in the container that are greater or equal to low and stricly lower than high.
spatial::open_region_iterator<T>
spatial::open_region_iterator<const T>
With this specialization, it will return all elements in the container that are strictly greater than low and stricly lower than high.
spatial::closed_region_iterator<T>
spatial::closed_region_iterator<const T>
With this specialization, it will return all elements in the container that are greater or equal to low and lower or equal to high.
spatial::enclosed_region_iterator<T>
spatial::enclosed_region_iterator<const T>
For this specialization, T's value_compare type must be a model of the Generalized Comparison concept. If it does not meet these requirements, code needing this iterator will not compile. This iterator is best used on spatial::box_multiset family of containers: it will return all boxes that are strictly enclosed into a user-defined box, specified when the iterator is constructed.
spatial::enclosed_region_iterator<T>
spatial::enclosed_region_iterator<const T>
For this specialization, T's value_compare type must be also be a model of the Generalized Comparison concept. If it does not meet these requirements, code needing this iterator will not compile. This iterator is best used on spatial::box_multiset family of containers: it will return all boxes that are overlapping with a user-defined box, specified when the iterator is constructed.
spatial::neighbor_iterator<T, M>
spatial::neighbor_iterator<const T, M>
M is a model of Metric. This iterator returns all elements in the container, in sequence from closest to furthest of a target value. This iterator performs a nearest neighbor search, and it is as precise as M allows it to be.
spatial::neighbor_iterator<T>
spatial::neighbor_iterator<const T>
In this form, this iterator will assume that an nearest neighbor search is performed in an euclidian space and that distances are expressed with the type double.
spatial::euclidian_neighbor_iterator<T, L, D>
spatial::euclidian_neighbor_iterator<const T, L, D>
In this specialization a nearest neighbor search is performed in euclidian space, with L being the type used to represent distances, and D begin a model of the Difference concept. D is optional if it can be deduced from the value_compare type from the container. Example: if the container is using spatial::bracket_less as value_compare, then D will be guessed as spatial::bracket_minus.
spatial::quadrance_neighbor_iterator<T, L, D>
spatial::quadrance_neighbor_iterator<const T, L, D>
In this specialization a nearest neighbor search is performed in euclidian space, but with distances that are expressed as the square of their values: this is the quadrance. This iterator generally works faster than the previous one, because the square roots do not need to be computed. However it is more prone to overflow if the distances being computed are covering most of the type L range.
spatial::manhattan_neighbor_iterator<T, L, D>
spatial::manhattan_neighbor_iterator<const T, L, D>
This specialization calculates metrics also in euclidian space, but using the manhattan (or taxicab) metric. This metric is a very fast metric, and can give a good (but coarse) approximation of the euclidian metric.

Common Iterators Interface

Performance of the Iterators

When choosing between queries, it is necessary to understand the performance assumptions of each queries.