DList.Range magically becomes empty.

Tobias Pankrath via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Feb 25 01:07:16 PST 2015


import std.container;
import std.stdio;


void main()
{
    DList!int list;
    Array!(DList!int.Range) stack;
    foreach(i; 0 .. 4)
    {
       list.stableInsertBack(i);
       stack.insertBack(list[]);
    }

    writefln("list: %s", list[]); // fine
    writefln("stack: %s", stack[]); //fine

    foreach(s; stack[])
       writefln("s: %s", s); // all s are empty?

    writefln("stack: %s", stack[]); //not fine
}

It prints:

list: [0, 1, 2, 3]
stack: [[0], [0, 1], [0, 1, 2], [0, 1, 2, 3]]
s: []
s: []
s: []
s: []
stack: [[], [], [], []]


More information about the Digitalmars-d-learn mailing list