Regarding std.array.Appender

Timon Gehr timon.gehr at gmx.ch
Thu Mar 1 08:38:57 PST 2012


On 03/01/2012 03:40 AM, Jonathan M Davis wrote:
> On Wednesday, February 29, 2012 21:23:54 bearophile wrote:
>> Jonathan M Davis:
>>>> put is a function on output ranges, and Appender is an output range.
>>>
>>> Also, given that it doesn't define ~ (and it wouldn't really make sense
>>> for it to), it would be very weird IMHO to define ~=.
>>
>> I don't understand why that's weird.
>> In Java you can't overload an append operator, so using a method is right.
>> But for me it's weird that Appender doesn't use the D operator to _append_.
>> I sometimes use "add" instead of "put" by mistake, forgetting the right
>> method name, because I find it quite unnatural. If Appender needs a put,
>> then I suggest to give it both "put" method and "~=" operator.
>
> Would you define += without defining +? Or *= without defining *? It strikes me
> as a misuse of operator overloading if you have an opOpAssign without its
> corresponding opBinary.
>
> - Jonathan M Davis

It is not the same thing. a=a~b has different semantics from a~=b;


More information about the Digitalmars-d-learn mailing list