Having an abstraction that encapsulates a pair of iterators is very useful.
The standard library uses
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:
is templated on an Forward
Traversal Iterator and should be used whenever fairly general code
is needed. The
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
Both classes can be used as ranges since they implement the minimal interface required for this to work automatically.