Article View: comp.std.c++
Article #2043Output iterators
From: Dan Zigmond
Date: Tue, 26 Sep 1995 19:50
Date: Tue, 26 Sep 1995 19:50
66 lines
2864 bytes
2864 bytes
I'm sorry if this has already been discussed here (or elsewhere). I've
been reading the 28 April 1995 draft of the C++ standard and am wondering
why output iterators are not required to define operator== or operator!=
(or, more accurately, why it is not required that a == b or a != v be
defined when a and be are output iterators).
One consequence of this, as far as I can tell, is that algorithms like fill
and generate must be defined to take forward iterators rather than output
iterators. I've looked at the code in the HP STL, and it looks like this:
template <class ForwardIterator, class Generator>
void generate(ForwardIterator first, ForwardIterator last, Generator gen) {
while (first != last) *first++ = gen();
}
template <class ForwardIterator, class T>
void fill(ForwardIterator first, ForwardIterator last, const T& value) {
while (first != last) *first++ = value;
}
Intuitively, this doesn't seem to require forward iterator semantics
because we are never dereferencing first or last for read purposes.
Comapre, for example, to transform (also from the HP implementation):
template <class InputIterator, class OutputIterator, class UnaryOperation>
OutputIterator transform(InputIterator first, InputIterator last,
OutputIterator result, UnaryOperation op) {
while (first != last) *result++ = op(*first++);
return result;
}
The only difference I see between result in transform anf first in fill and
generate is that result is not compared using operator!=, where as the
iterators in fill and generate are.
Is there some reason why output iterators cannot in general be compared
using the standard operators? I'm sure there's a rationale for this that
I'm missing. Could someone tell me what it is?
Dan
-----------------------
Dan Zigmond
djz@west.net (prefered)
djz@avasoft.com (possible delay)
Avatar Software, Inc.
(303) 415-9815
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: 2.6.2
mQCPAzAmSSQAAAEEAMXr4YMu8GIhvvW4fEd+CEOsV7PkD/7plppDeN2C8iWgvj5K
+DHYlgzNh2sF1OsS/irKGNlbdXPJChOmsg5EelW/ZTVl6bJYqJSCBFTKSa1RA5P4
XFv511f+B/k8TCuIOPx+NyaTTrYxaTd841QLvadGjLjWBvNMJkV1/Q6ozQpNABEB
AAG0I0RhbmllbCBKLiBaaWdtb25kIDxkanpAYXZhc29mdC5jb20+
=Tx0L
-----END PGP PUBLIC KEY BLOCK-----
---
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID:
<MATT.95Sep26125037@physics2.Berkeley.EDU>Path:
arc1-ca.pugleaf.net!128.32.155.1!mattShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!128.32.155.1!matt From: djz@west.net (Dan Zigmond) Newsgroups: comp.std.c++ Subject: Output iterators Date: 26 Sep 1995 19:50:37 GMT Organization: <none> Approved: matt@physics2.Berkeley.EDU (Matt Austern) Message-ID: <MATT.95Sep26125037@physics2.Berkeley.EDU> NNTP-Posting-Host: physics2.berkeley.edu