🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by Dan Zigmond Tue, 26 Sep 1995 19:50
Output iterators
#2043
Author: Dan Zigmond
Date: Tue, 26 Sep 1995 19:50
66 lines
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. ]
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads