More D newb questions.

Janice Caron caron800 at googlemail.com
Tue May 6 11:31:32 PDT 2008


On 06/05/2008, Steven Schveighoffer <schveiguy at yahoo.com> wrote:
> I just think your other points are invalid.

I think Walter is spot on. This is an OPERATOR, not a function.
Operators are supposed to have well defined semantics. The plus sign
is supposed to mean addition. The minus sign is supposed to mean
subtraction. The tilde sign is supposed to mean concatenation of
contents.

It is appropriate for structs which are custom containers to overload
opCat to emulate contanation of container contents, but overloading
opCat to do anything else violates the principle of least surprise,
and is every bit as bad as it would be to overload opAdd to create
arrays.

Like any other operator, the ~ operator shouldn't be treated like an
ad hoc function. Sure - you can overload foo() to do whatever you
want. But please don't treat opXxxx() in the same way.

As far as generic programming is concerned, I think there is a
reasonable expection that classes will not overload opCat(), except to
emulate an array, and authors of template code should be entitled to
make that assumption, just as they are equally entitled to assume that
T + T will have have type T.



More information about the Digitalmars-d mailing list