
Andrey Semashev wrote:
Yes, in general default-constructed iterators are singular and they cannot be used reliably. However, not all iterators behave that way. Pointers, for example, are NULL on default-initialization (which is used in the default constructor of the iterator_range class). I can well have my own iterators that are default-constructible and allow comparison in this state. And I don't understand why an iterator range of these iterators suddenly restricts me from being able to compare these iterators in empty(), for example.
Iterators where default-construction leads to a valid past-the-end iterator for all sequences are a fairly special case of iterators, even if they happen to be quite common. However, that is certainly not guaranteed by the iterator concepts. Therefore, when you deal with iterators in a generic way, you should not assume such a thing. iterator_range being a generic tool, it wants to maintain the invariants which are necessary to make it work whatever its parameters are, even if those invariants happen not to be necessary for some parameters. Maybe if your iterators are so peculiar and you want to be able to rely on that property, you should use something else than iterator_range which is designed for all iterators.