![]() |
Home | Libraries | People | FAQ | More |
Having an abstraction that encapsulates a pair of iterators is very useful.
The standard library uses std::pair
in
some circumstances, but that class is cumbersome to use because we need to
specify two template arguments, and for all range algorithm purposes we must
enforce the two template arguments to be the same. Moreover, std::pair<iterator,iterator>
is hardly self-documenting whereas more
domain specific class names are. Therefore these two classes are provided:
iterator_range
sub_range
join
The iterator_range
class is
templated on an Forward
Traversal Iterator and should be used whenever fairly general code
is needed. The sub_range
class
is templated on an Forward Range
and it is less general, but a bit easier to use since its template argument
is easier to specify. The biggest difference is, however, that a sub_range
can propagate constness because
it knows what a corresponding const_iterator
is.
Both classes can be used as ranges since they implement the minimal interface required for this to work automatically.