Per the (excellent) question C++ OutputIterator post-increment requirements, we observe that for a dereferenceable and incrementable value r
of OutputIter
This issue was raised in 2004 as defect 485, and the wording in n3066 clarifies the issue, requiring that an output iterator need only support a sequence of alternating increments and dereference/assignments. So in your example, r
need not be incrementable after the first ++r
, unless there is an intervening dereference/assignment. This behavior is also required by SGI's STL (see footnote 3). As you mentioned above, n3225 appeared without the fixes from n3066, so defect 2035 was raised; but alas the fix did not make it into the published version of C++11 (ISO/IEC 14882:2011).
Furthermore, defect 2035 says that a
(from X a(r++);
) cannot be used like *a = 0
:
"After this operation [i.e.,
++r
]r
is not required to be incrementable and any copies of the previous value ofr
are no longer required to be dereferenceable or incrementable."
There are situations where this may aid the implementation (in terms of simplicity): see e.g. this question on ostream_iterator
, where such (invalid) double increments are ignored simply returning *this
; only a dereference/assignment causes the ostream_iterator
to actually increment.