This bug was introduced in 2.048, as is 2.047 iota stops but fails shortly after:
src/phobos/std/algorithm.d(279): Enforcement failed
Comment #3 by eco — 2012-02-01T13:21:38Z
2.057 seems to handle this situation (trying to reduce an empty range but not offering a seed) by throwing an appropriate exception:
object.Exception@C:\D\dmd2\windows\bin\..\..\src\phobos\std\algorithm.d(662): Cannot reduce an empty range w/o an explicit seed value.
I believe this should be closed. Also, not sure why this is set as an optlink issue.
Comment #4 by hsteoh — 2013-01-03T20:24:38Z
In latest git head, throws an exception. Is this acceptable (should the bug be closed)?
Or is it better to have reduce return (ElementType!R).init?
Comment #5 by bearophile_hugs — 2013-01-04T17:53:04Z
(In reply to comment #4)
> In latest git head, throws an exception. Is this acceptable (should the bug be
> closed)?
>
> Or is it better to have reduce return (ElementType!R).init?
The reduce of Python returns the start value:
>>> reduce(lambda a,b: a * b, [], 0)
0
Comment #6 by hsteoh — 2013-01-04T18:17:16Z
The problem here is that no start value is given.
Comment #7 by bearophile_hugs — 2013-01-04T18:36:53Z
(In reply to comment #6)
> The problem here is that no start value is given.
In this case Python raises an error. I think this is acceptable:
>>> reduce(lambda a,b: a * b, [])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: reduce() of empty sequence with no initial value
Comment #8 by hsteoh — 2013-01-04T22:11:08Z
In that case, we should probably close the bug, since the latest Phobos throws an exception upon calling reduce() with an empty range and no start value.
Comment #9 by andrei — 2013-03-12T21:02:09Z
Looks good: exception thrown if no seed, seed returned if it exists.