opStar

Janice Caron caron800 at googlemail.com
Sat Nov 10 07:32:24 PST 2007


On 11/10/07, Michel Fortin <michel.fortin at michelf.com> wrote:
> But seriously, operator overloading's goal is to allow the programmer
> to use a consistent syntax for native and non-native types. It seem to
> me that opStar is pretty limited compared to other operators which can
> be overriden. Not only it doesn't allow you to use a simple syntax for
> calling aggregate's members -- as in `a.b` instead of `(*a).b` -- but
> since D doesn't have a reference type as you have in C++, implementing
> something as simple as `*a = b` is going to be pretty complicated for
> any non-object value (objects are reference types in D).

Indeed. And given that D has always (until now) discouraged the use of
pointers, and encouraged things like arrays and the "ref" parameter
storage class in their place, I have never actually been tempted to
even /use/ pointers, let alone emulate them.

It's always been easy enough to mimic a pointer as a dynamic array
with one element (because of how arrays are implemented in D). Smart
arrays have always been overloadable, and

    a[0] = b;

is just as workable as

    b = a[0];

The same cannot be said of *a. Also

    a[0].member

is no more keystrokes than

    (*a).member

(and doesn't involve the shift key).


> So, I'm left wondering about why this operator was made overridable in
> the first place if it's so limited.

Yeah - I'd like to know that too. I'm not knocking it, mind - I just
haven't grasped the intent yet.



More information about the Digitalmars-d mailing list