opStar

Janice Caron caron800 at googlemail.com
Sun Nov 11 00:37:15 PST 2007


On 11/11/07, Walter Bright <newshound1 at digitalmars.com> wrote:
> Janice Caron wrote:
> > So, we can write p.m for real pointers, but we have to write (*p).m
> > for classes that implement opStar()? That seems inconsistent.
>
> Not really. You cannot overload references in C++, either.

Nice looking herring there. I like the cool red color. Anyway, back on
topic... (*p).m for iterators, versus p.m for pointers. That seems
inconsistent.

The way I see it is, (as others have pointed out), if iterators are to
be of any use as "smart pointers", then they need to act like
pointers. If they don't , then you might just as well use a member
function like .val or .deref.

If you want to force people to write (*p).m for real pointers, so that
generic programming can accept either, then you're probably going to
have to deprecate p.m for pointers.


> > What's opStar for, if not to implement iterators?
>
> For iterators.

Interesting. But I still don't understand how opStar() would help us do:
    *p++ = *q++;


> Should a class be used as an iterator? I can't see how
> that would make sense anyway.
I don't recall anyone claiming that an iterator need be a class.
Everything written above works just as well if you substitute "struct"
for "class".



More information about the Digitalmars-d mailing list