D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 23094 - std.range.generate calls fun more than necessary
Summary: std.range.generate calls fun more than necessary
Status: RESOLVED DUPLICATE of issue 19587
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: x86_64 Linux
: P1 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-05-05 19:51 UTC by Remi Thebault
Modified: 2022-05-06 16:50 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Remi Thebault 2022-05-05 19:51:47 UTC
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 Remi Thebault 2022-05-05 19:53:13 UTC
DMD64 D Compiler v2.099.1 (Linux x86_64)
Comment 2 Remi Thebault 2022-05-06 16:50:40 UTC

*** This issue has been marked as a duplicate of issue 19587 ***