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

Paul Backus snarwin at gmail.com
Wed Oct 28 15:30:28 UTC 2020


On Wednesday, 28 October 2020 at 15:25:18 UTC, Ola Fosheim 
Grøstad wrote:
> On Wednesday, 28 October 2020 at 15:05:19 UTC, Paul Backus 
> wrote:
>> You can add an initial value outside of the fold expression:
>>
>>     false || Tup == 10 || ...
>
> Ok, but the problem is in generic code. You could adopt init as 
> the initial value for fold, but it fails miserably for floats 
> as they don't have 0 as the init, but NaN...
>
> Will it work with overloads so that the initial value can be a 
> completely different type? (If you want to trap empty tuples, 
> but have no unused value.)

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.


More information about the Digitalmars-d mailing list