I've read on cppreference that with C++20, it's possible to omit specifying the type aliases reference
, pointer
and iterator_category
when defining a new iterator.
In this case, the corresponding aliases in std::iterator_traits
will have "default" values.
The details of this are a bit confusing to me, so I'm trying to split this topic into answerable questions.
So, my first question is:
Are all (or some) of these "default" aliases guaranteed to be correct?
As I understand it, the iterator_category
tags are based on the C++17 named requirements.
If an iterator satisfies the forward iterator requirement (but not the bidirectional requirement), its tag should be forward_iterator_tag
.
I'm specifically worried about the distinction between forward_iterator_tag
and input_iterator_tag
.
Forward iterators have to be able to be used in multipass algorithms, but I don't think the compiler checks that this is the case.
Are there cases where I can know that the "default" aliases will be correct (e.g. an output iterator is always classified correctly, or the default reference
alias is always correct)?