opStar

Janice Caron caron800 at googlemail.com
Mon Nov 12 09:25:31 PST 2007


On 11/12/07, Walter Bright <newshound1 at digitalmars.com> wrote:
> > You also haven't addressed the point that since no function, opStar
> > included, can return a reference to a struct, then we are forced to
> > return a pointer to a struct, so now your iterator behaves not like a
> > pointer, but a pointer to a pointer.
>
> Iterators should be very small value types. I don't see why one would be
> returning a reference to an iterator.

OK, I'm not being understood.

Assume you have this defined...

    struct VeryLargeStruct { /*...*/ }

Now have a collection of those things.

    class CollectionOfVeryLargeStructs { /*...*/ }

Then you get an iterator

    CollectionOfVeryLargeStructs c;
    IteratorToVeryLargeStruct p = c.begin();

p itself is very small, being an instance of
IteratorToVeryLargeStruct. My question relates, not to p, but to
p.opStar(). What type should p.opStar() return?

Should it return (by value) a VeryLargeStruct?

Or should it return a VeryLargeStruct* ?

(Of course, in C++, we'd just have operator*() return a
VeryLargeStuct&. Problem solved).

If the latter, then p is behaving like a pointer-to-a-pointer, not a
pointer, and now you'd have to (**p), not (*p), to reach an actual
VeryLargeStruct, and you'd have to write (**p).m to access the members
thereof.

You see?



More information about the Digitalmars-d mailing list