Stack

A basic stack with push, and pop

Constructors

this
this()
Undocumented in source.

Destructor

~this
~this()
Undocumented in source.

Members

Functions

clear
void clear()

Empties the stack

pop
T[] pop(uinteger count)

Reads and removes an array of items from the stack, if not enough items are left, throws Exception

pop
T pop()

Reads and removes an item from the stack, if no more items are present, throws Exception

push
void push(T item)

Appends an item to the stack

push
void push(T[] items)

Appends an array of items to the stack

Properties

count
uinteger count [@property getter]

Number of items in stack

Examples

Unittests for Stack

Stack!ubyte stack = new Stack!ubyte;
//`Stack.push` and `Stack.pop`
stack.push(0);
stack.push([1, 2]);
assert(stack.pop == 2);
assert(stack.pop(2) == [1, 0]);
stack.push([1, 0]);
assert(stack.pop!(true)(2) == [1, 0]);
//`Stack.clear` && `Stack.count`
stack.push(0);
assert(stack.count == 1);
stack.clear;
assert(stack.count == 0);
stack.destroy;

Meta