Алексей М.
Алексей М.

Reputation: 157

How to output the contents of a DList as an array to the console?

I'm just started to learn Dlang.

Need to output DList!int as an array - [1, 2, 3].

import std.stdio : writeln;
import std.container.dlist : DList;

void main()
{
    DList!int list;
    list.insertFront(1);
    list.insertBack([2, 3]);
    writeln(list); // prints DList!int(7F50A689A000) 
}

Upvotes: 2

Views: 93

Answers (1)

DejanLekic
DejanLekic

Reputation: 19787

You were very close. You just needed the [] to make a Range out of it, and then the writeln() line would work as you expected:

writeln(list[]); // prints [1, 2, 3]

Upvotes: 3

Related Questions