Struct Collection

Array based collection of items.

struct Collection(T, bool ownItems = false);

Retains item order when during add/remove operations.

Optionally destroys removed objects when instanciated with ownItems = true.

Fields

NameTypeDescription
_items T[]
_len size_t

Properties

NameTypeDescription
back[get] Tpeek last item
empty[get] boolreturns true if there are no items in collection
front[get] Tpeek first item
length[get] size_treturns number of items in collection
length[set] size_treturns number of items in collection
peekBack[get] Tpeek last item
peekFront[get] Tpeek first item
popBack[get] Tremove last item
popFront[get] Tremove first item
size[get] size_treturns currently allocated capacity (may be more than length)
size[set] size_tchange capacity (e.g. to reserve big space to avoid multiple reallocations)

Methods

NameDescription
add (item, index) insert new item in specified position
addAll (v) add all items from other collection
clear () remove all items
indexOf (item) returns index of first occurence of item, size_t.max if not found
opApply (op) support of foreach with reference
opIndex (index) access item by index
opOpAssign (item) support for appending (~=, +=) and removing by value (-=)
pushBack (item) insert item at end of collection
pushFront (item) insert item at beginning of collection
remove (index) remove single item, returning removed item
removeValue (value) remove single item by value - if present in collection, returning true if item was found and removed