Nasty corner case behaviour

Suleyman sahmi.soulaimane at gmail.com
Fri Apr 19 01:21:16 UTC 2019


On Thursday, 18 April 2019 at 05:01:17 UTC, H. S. Teoh wrote:
> ...

The value of flag is lost.

To easily see this make flag an int.

    import std.algorithm : filter, map;
    import std.stdio;

    struct S {
        int flag;
        auto method() {
            return [ 1 ].filter!((e) {
                            writeln("\nflag: ", flag);
                            return flag == 10;
                        });
        }
    }

    void main() {
        auto s = S(10);

        auto arr = [ s ];

        auto mappedArray = arr.map!(e => e.method);
        writeln(mappedArray);
    }

  Expected output:

        [[
        flag: 10
        1]]

  Actual output:

        [[
        flag: 1872694912
        ]]




More information about the Digitalmars-d mailing list