Why are ForwardIterators required to model DefaultConstructible?
c++, iterator
Solution
It is there to ease the use of these kind of iterators, for both the standard algorithms and client users.
For example (remember that `RandomAccessIterator` is a subtype of `ForwardIterator`):
template <class RandomAccessIterator>
void sort ( RandomAccessIterator first, RandomAccessIterator last )
{
RandomAccessIterator pivot, i, j;
//do your sorting algorithm
}
If they were not default constructible you would need to assign them to `first` or `last` just for it to compile.
You do not need it to be set to a default value. Any use of such uninitialized iterator is undefined. Not that is would not be wise to add some check, particularly in debug builds.
And no, you should not throw in the default constructor. It would be technically conformant, but many algorithms will fail unexpectedly.
Problem
I cannot seem to find any standard algorithms that would demonstrate the requirement for default-constructing a `ForwardIterator`. Is there any actual reason for it, or am I safe to ignore it?