Annex D (informative) Compatibility [diff]

D.1 C++ and Ranges [diff.cpp]

D.1.4 Iterators and Default-Constructibility [diff.cpp.defaultconstruct]

In today's STL, iterators need not be default-constructible. The Iterator concept described in this document requires default-constructibility. This could potentially cause breakage in users' code. Also, it makes the implementation of some types of iterators more complicated. Any iterator that has members that are not default constructible (e.g., an iterator that contains a lambda that has captured by reference) must take special steps to provide default-constructibility (e.g., by wrapping non-default-constructible types in something like std::optional, as specified in the C++17 Working Draft N4618 §20.6). This can weaken class invariants.

The guarantee of default-constructibility simplifies the implementation of much iterator- and range-based code that would otherwise need to wrap iterators in std::optional. But the needs of backward-compatibility, the extra complexity to iterator implementors, and the weakened invariants may prove to be too great a burden.

We may in fact go even farther and remove the requirement of default-constructibility from the Semiregular concept. Time and experience will give us guidance here.