Topic: Possible error in the definition of output iterators


Author: chris@bubblescope.net (chris)
Date: Thu, 7 Oct 2004 15:43:09 GMT
Raw View
Looking at 24.1.2 in the C++ standard, there is some strangeness with
regards output iterators.

The two main constraints appear to be:

Assignment through the same iterator happens only once.
Algorithms on output iterators should never attempt to pass through the
same iterator twice.

However, nothing is said about if a copy of an iterator is the same
iterator, or that an assignment must be made before incrementing an
iterator (as is required for example in sgi's stl implementation.

Therefore I am not clear on which of the following are legal (although I
suspect they should all be forbidden)

Given an output iterator type X, which takes ints and where a is a valid
iterator which has not yet been written to, which of the following are
allowed?

++a;
// Forbidden by sgi
X u(a); u=1; a=1;
// Probably supposed to be forbidden
X u(a); ++a; u=1;
// If this is forbidden that makes implementing the last requirement
// *r++=t difficult I suspect
X u(a); ++a; a=1; u=1;
// Is this defined? I suspect it shouldn't be
X u(a); X x(u); X y(x); X z(y);
// How far can I chain along? Which of these can I write to?
// I read the standard as saying any, in any order.

Sorry if this has been dealt with before, but I would appresiate any
comments / suggestions. Could this need a DR?

Thank you,

Chris

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]