https://dpaste.dzfl.pl/cd605899d050

why this code cannot convert to foreach (over Structs and Classes with Ranges).

    auto h = new BinaryHeap!(int[])(new int[0]);
    typeof(h).stringof.writeln;
    static assert(isInputRange!(typeof(h)));
    h.insert(3);
    h.insert(1);
    h.insert(2);
    // Error: invalid foreach aggregate `h`
    // foreach (e; h) e.writeln;
    for (; !h.empty; h.popFront()) {
      auto e = h.front();
      e.writeln;
    }


https://dlang.org/spec/statement.html#foreach-with-ranges

Reply via email to