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
| Name | Type | Description |
|---|---|---|
_items
|
T[] | |
_len
|
size_t |
Properties
| Name | Type | Description |
|---|---|---|
back[get]
|
T | peek last item |
empty[get]
|
bool | returns true if there are no items in collection |
front[get]
|
T | peek first item |
length[get]
|
size_t | returns number of items in collection |
length[set]
|
size_t | returns number of items in collection |
peekBack[get]
|
T | peek last item |
peekFront[get]
|
T | peek first item |
popBack[get]
|
T | remove last item |
popFront[get]
|
T | remove first item |
size[get]
|
size_t | returns currently allocated capacity (may be more than length) |
size[set]
|
size_t | change capacity (e.g. to reserve big space to avoid multiple reallocations) |
Methods
| Name | Description |
|---|---|
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 |