Both irange
and counting_range
model a random access range for integer types. As counting_range
s documentation points out, its iterator category is determined according to the following algorithm:
if (CategoryOrTraversal is not use_default)
return CategoryOrTraversal
else if (numeric_limits<Incrementable>::is_specialized)
return iterator-category(random_access_traversal_tag, Incrementable, const Incrementable&)
else
return iterator-category(iterator_traversal<Incrementable>::type, Incrementable, const Incrementable&)
Therefore, for simple ranges such as boost::irange(0, 10)
and boost::counting_range(0, 10)
there is effectively no difference (aside from the types of each range, of course!).
However, irange
also supports iteration with a different step size, e.g., boost::irange(0, 10, 2)
, and counting_range
also supports types that are only incrementable and do not fully model an integer.