Boost logo

Boost :

From: John E. Potter (jpotter_at_[hidden])
Date: 2001-06-07 10:14:35


On Thu, 7 Jun 2001, David Abrahams wrote:

> From: "John E. Potter" <jpotter_at_[hidden]>

> > Not a problem for a language with modifiable rvalues. Operator= is
> > a member.
>
> I often forget whether it's classes or built-in types that can be modified
> in that way. When it's a member function, you're not binding X(a) to a
> non-const reference?

Right. I can neither bind an rvalue to a non-const reference nor take
its address, but the implementation can magically produce an rvalue
called this which acts like a poiinter to the non-const rvalue.

> Is this the standard's way of saying "use a self-proxy"?

I think that it is the standard's way of saying that all known output
iterators at the time were self-proxies. I can write an iterator that
will work in all algorithms which specify an output_iterator yet not
meet the requirements for an output iterator. Note also that no
standard iterator of any other type meets the requirements of an
output iterator. For a pointer, I must say *p = t, but the standard
requires p = t. Is it a defect or does it pass because p = t is
equivalent to P(p) = t, they are both syntax errors? Is the intent
to require a = t or just allow it? I think the intent was to say
that all copies of an output iterator are equivalent, but I don't
see any reason to require that either, but it should be allowed.

> The question remains, however: what is the type of t?

Anything which may be used in the expression *a = t. There could be
many different types. You don't want me writing
my_cute_ostream_iterator with operator= for char, int, and double?
Note that for ostream_iterator<int> it, *it = 5, *it = 'X', *it = 3.14
are equally valid. My_cute_ostream_iterator would produce nicer
results.

I once wanted the value_type of an output iterator in an algorithm,
but knowing what the algorithm did and the value_type of the
input iterator allowed me to declare a local of an appropriate
type. It might not be the same as the output iterator, but the
assignment would work.

John


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk