BDE 4.14.0 Production release
|
Provide a pure input iterator capable of traversing a range.
This components provides a value-semantic class
, bsltf::InputIterator
, that defines an input iterator that supports the following operations:
The iterator is initializable with either a pointer into a range, or a non-pointer iterator over a contiguous range.
This iterator type is typically used to check algorithms for compatibility with input iterators. The goal is to make sure that their code is able to compile and work even with the most restrictive input iterator.
This section illustrates intended use of this component.
In the following example we use a bsltf::InputIterator
to test that an aggregation function compiles and works when instantiated with a pure input iterator.
First, we define a function sum
that accepts two input iterators and returns the sum of all elements in range specified by them:
Then, in main
, we define an array of double
s and define InputIterators
pointing to the beginning and ending of it, initializing the iterators with pointers:
Next, we call sum
with the two iterators, and observe that its yields the expected result, and because it compiles, we know that sum
did not attempt any operations on the iterators other than those defined for the most basic input iterator:
Then, we illustrate that we can just make begin
and end
iterators from the array directly with the begin
and end
class methods of the InputIteratorUtil
class.
Now, we make an std::vector
containing the elements of myArray
:
Finally, we call sum
using, again, the begin
and end
class methods to create iterators for it directly from our vector
: