std.container.dlist

This module implements a generic doubly-linked list container. It can be used as a queue, dequeue or stack.

This module is a submodule of std.container.

Public Imports

std.container.util
public import std.container.util;

Members

Structs

DList
struct DList(T)

Implements a doubly-linked list.

Examples

1 import std.algorithm.comparison : equal;
2 import std.container : DList;
3 
4 auto s = DList!int(1, 2, 3);
5 assert(equal(s[], [1, 2, 3]));
6 
7 s.removeFront();
8 assert(equal(s[], [2, 3]));
9 s.removeBack();
10 assert(equal(s[], [2]));
11 
12 s.insertFront([4, 5]);
13 assert(equal(s[], [4, 5, 2]));
14 s.insertBack([6, 7]);
15 assert(equal(s[], [4, 5, 2, 6, 7]));
16 
17 // If you want to apply range operations, simply slice it.
18 import std.algorithm.searching : countUntil;
19 import std.range : popFrontN, popBackN, walkLength;
20 
21 auto sl = DList!int([1, 2, 3, 4, 5]);
22 assert(countUntil(sl[], 2) == 1);
23 
24 auto r = sl[];
25 popFrontN(r, 2);
26 popBackN(r, 2);
27 assert(r.equal([3]));
28 assert(walkLength(r) == 1);
29 
30 // DList.Range can be used to remove elements from the list it spans
31 auto nl = DList!int([1, 2, 3, 4, 5]);
32 for (auto rn = nl[]; !rn.empty;)
33     if (rn.front % 2 == 0)
34         nl.popFirstOf(rn);
35     else
36         rn.popFront();
37 assert(equal(nl[], [1, 3, 5]));
38 auto rs = nl[];
39 rs.popFront();
40 nl.remove(rs);
41 assert(equal(nl[], [1]));

Meta

License

Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at ).

Suggestion Box / Bug Report