[Issue 19823] std.range.dropOne doesn't drop the element when called after std.algorithm.iteration.filter

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Jun 13 18:38:17 UTC 2019


https://issues.dlang.org/show_bug.cgi?id=19823

Jonathan M Davis <issues.dlang at jmdavisProg.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |issues.dlang at jmdavisProg.co
                   |                            |m

--- Comment #3 from Jonathan M Davis <issues.dlang at jmdavisProg.com> ---
dropOne isn't actually the problem at all. Rather, it looks like the problem is
with either `Filter`'s `popFront` or with the code that dmd is generating. This
reduced test case has the same problem:

    void main()
    {
        import std.algorithm.comparison : equal;
        import std.algorithm.iteration : filter;

        auto arr = [1, 2, 3, 4];

        auto result = arr.filter!(a => a != 1)();
        assert(result.save.equal([2, 3, 4]));

        result.popFront();
        assert(result.equal([3, 4]));
    }


For some reason, `popFront` is not doing anything with this particular example,
and the second assertion fails. Rather if the result is printed after
`popFront`, it's equivalent to [2, 3, 4], and changing the second assertion to

    assert(result.equal([2, 3, 4]));

makes it pass. So, clearly, `popFront` is doing nothing for some reason.

--


More information about the Digitalmars-d-bugs mailing list