Bug 23094 – std.range.generate calls fun more than necessary

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2022-05-05T19:51:47Z
Last change time
2022-05-06T16:50:40Z
Assigned to
No Owner
Creator
Remi Thebault

Comments

Comment #0 by remi.thebault — 2022-05-05T19:51:47Z
The following unit test fails (i == 2): unittest { import std.array; import std.random; import std.range; int someFun() { return uniform(0, 2000); } int i = 0; const arr = generate!(() { ++i; return someFun(); }).take(1).array; assert(arr.length == 1); assert(i == 1, "generate called fun more than once"); }
Comment #1 by remi.thebault — 2022-05-05T19:53:13Z
DMD64 D Compiler v2.099.1 (Linux x86_64)
Comment #2 by remi.thebault — 2022-05-06T16:50:40Z
*** This issue has been marked as a duplicate of issue 19587 ***