Discussion Thread: DIP 1037--Add Unary Operator ...--Community Review Round 1

Paul Backus snarwin at gmail.com
Wed Oct 28 17:48:21 UTC 2020


On Wednesday, 28 October 2020 at 15:43:24 UTC, Ola Fosheim 
Grøstad wrote:
> On Wednesday, 28 October 2020 at 15:30:28 UTC, Paul Backus 
> wrote:
>> Generic code can deal with this the same way 
>> std.algorithm.reduce does: by taking the initial value as a 
>> parameter, or by requiring that the tuple be non-empty.
>
> What I meant is what if the library author provided a function 
> for "numbers", but never tested the code with floats. If the 
> initial value is required then the library author would have 
> remembered to set the initial value to "cast(T)0" for addition 
> or "cast(T)1" for multiplication.

The library author could just as easily use `T.init` as the 
initial value, and if the code is never tested with floats, it 
will appear to work just fine. So requiring an initial value does 
nothing to prevent this hypothetical bug.


More information about the Digitalmars-d mailing list