Struct DList

Doubly-linked list.

struct DList(T) ;

DList can be also used as a queue. Elements can be enqueued with DList.insertBack. To process the queue a for-loop comes in handy:

for (; !dlist.empty; dlist.removeFront())
{
 do_something_with(dlist.front);
}

Constructors

NameDescription
this (init, allocator) Creates a new DList with the elements from a static array.
this (init, allocator) Creates a new DList with the elements from an input range.
this (len, init, allocator) Creates a new DList.
this (init, allocator) Initializes this list from another one.

Properties

NameTypeDescription
back[get] inout(T)
empty[get] bool
front[get] inout(T)

Methods

NameDescription
clear () Removes all contents from the list.
insertAfter (r, el) Inserts new elements after r.
insertAfter (r, el) Inserts elements from a static array after r.
insertBack (el) Inserts a new element at the end.
insertBefore (r, el) Inserts new elements before r.
insertBefore (r, el) Inserts elements from a static array before r.
insertFront (el) Inserts a new element at the beginning.
opAssign (that) Assigns another list.
opAssign (that) Assigns an input range.
opAssign (that) Assigns another list.
opAssign (that) Assigns a static array.
opEquals (that) Comparison for equality.
opIndex ()
popFirstOf (range) Removes the front or back element of the range from the list respectively.
popLastOf (range) Removes the front or back element of the range from the list respectively.
remove (r) Removes r from the list.
removeBack () Removes the front or back element.
removeBack (howMany) Removes howMany elements from the list.
removeFront () Removes the front or back element.
removeFront (howMany) Removes howMany elements from the list.

Aliases

NameDescription
ConstRange The range types for DList.
insert Inserts a new element at the end.
Range The range types for DList.

Parameters

NameDescription
T Content type.

Example

DList!int l;
size_t i;

l.insertFront(5);
l.insertFront(4);
l.insertFront(9);
foreach (e; l)
{
    assert(i != 0 || e == 9);
    assert(i != 1 || e == 4);
    assert(i != 2 || e == 5);
    ++i;
}
assert(i == 3);