C++ requires that an OutputIterator type X
support expressions of the form r++
, where r
is an instance of X
. This postfix increment must be semantically equivalent to:
(*) { X tmp = r; ++r; return tmp; }
and must return a type that is convertible to X const&
. In C++11, see 24.2.4 (this is not new, however). In the same section, it says
Algorithms on output iterators should never attempt to pass through the same iterator twice. They should be single pass algorithms.
Given (*), above, say I copy the return value like X a(r++);
Suppose
r
was dereferencable before incrementing, but was not dereferenced. Is it required thata
be dereferencable? If so, mustX a(r++); *a = t;
perform the same assignment as*r++ = t;
would have otherwise? Are there any (other) conditions ona
andr
?Otherwise, suppose
r
was dereferenced/assigned before incrementing, and its incremented value is (also) dereferencable. Which of the following (if any) are well-defined: (a)*a = t;
, (b)++a; *a = t;
, (c)*r = t;
?
Also see the follow-up: Dereference-assignment to a doubly incremented OutputIterator