SmallList

SmallList: inlineStorage, SmallList, ~SmallList, take, size, print, empty, capacity, operator[], operator[]=, operator[-], operator[-]=, first, last, data, push, pop, reserve, removeFirst, removeLast, clear, removeAt, contains, indexOf, iterator, find, map, filter, chain, sum, all, any, none

SmallListIterator: SmallListIterator, hasValue, value, increment, sum, toList

Functions: operator==

struct SmallList<Element, int N>

inlineStorage

@manuallyDestroy private Element[N] inlineStorage;

SmallList

SmallList()

Initializes an empty list.

SmallList(int size, Element value)

Initializes a list containing size copies of the given value.

SmallList<int M>(Element[M] elements)

~SmallList

~SmallList()

Frees the elements and backing storage.

take

SmallList<Element, N> take()

Moves the list out, leaving an empty list in its place.

size

int size()

Returns the number of elements in the list.

print

void print(OutputStream& stream)

Writes the elements to the given stream.

empty

bool empty()

Returns true if the list has no elements, otherwise false.

capacity

int capacity()

Returns the number of elements the list can store without allocating more memory.

operator[]

Element& operator[](int index)

Returns the element at the given index.

operator[]=

void operator[]=(int index, Element element)

Sets the element at the given index.

operator[-]

Element& operator[-](int index)

Returns a reference to the element at the given offset from the end. Offset 1 is the last element; out-of-bounds access aborts in debug and release-safe builds.

operator[-]=

void operator[-]=(int index, Element element)

Sets the element at the given offset from the end. Offset 1 is the last element; out-of-bounds access aborts in debug and release-safe builds.

first

Element& first()

Returns the first element.

last

Element& last()

Returns the last element.

data

Element[*] data()

Returns a pointer to the first element.

push

Element& push(Element element)

Adds the given element to the end of the list, returning a reference to it.

pop

Element pop()

Removes and returns the last element.

reserve

void reserve(int minimumCapacity)

Ensures that the capacity is large enough to store the given number of elements.

removeFirst

Element removeFirst()

Removes the first element from the list and returns it. Other elements are moved towards the beginning of the list by one index.

Element? removeFirst<Pred: bool(Element&)>(Pred shouldRemove)

Removes the first element satisfying the given condition and returns it, or null if none matches.

Element? removeFirst<T: Copyable, Pred: bool(T)>(Pred shouldRemove)

Removes the first element satisfying the given condition and returns it, or null if none matches.

removeLast

void removeLast()

Removes the last element from the list.

clear

void clear()

Removes all elements from the list, keeping the allocated buffer.

removeAt

Element removeAt(int index)

Removes the element at the given index from the list and returns it. Elements following the removed element are moved towards the beginning of the list by one index.

contains

bool contains(Element& value)

Returns true if the list contains an element equal to the given value.

indexOf

int? indexOf(Element& value)

Returns the index of the first element equal to the given value, or null if it's not found.

iterator

SmallListIterator<Element, N> iterator()

Returns an iterator over the elements.

find

Element&? find<Pred: bool(Element&)>(Pred predicate)

Returns the first element satisfying the predicate, or null.

Element&? find<T: Copyable, Pred: bool(T)>(Pred predicate)

Returns the first element satisfying the predicate, or null.

map

MappedIterator<Output, Element, SmallListIterator<Element, N>, Pred> map<Output, Pred: Output(Element&)>(Pred transform)

Lazily transforms the elements. Collect the results with toList().

MappedIterator<Output, Element, SmallListIterator<Element, N>, Pred> map<Output, T: Copyable, Pred: Output(T)>(Pred transform)

Lazily transforms the elements. Collect the results with toList().

filter

FilterIterator<Element, SmallListIterator<Element, N>, Pred> filter<Pred: bool(Element&)>(Pred include)

Lazily keeps the elements satisfying the predicate. Collect the results with toList().

FilterIterator<Element, SmallListIterator<Element, N>, Pred> filter<T: Copyable, Pred: bool(T)>(Pred include)

Lazily keeps the elements satisfying the predicate. Collect the results with toList().

chain

ChainIterator<Element, SmallListIterator<Element, N>, Other> chain<Other>(Other other)

Lazily appends another iterator's elements. Collect the results with toList().

sum

Element sum()

Returns the sum of the elements, or zero if there are none.

all

bool all<Pred: bool(Element&)>(Pred predicate)

Returns true if all elements satisfy the predicate.

bool all<T: Copyable, Pred: bool(T)>(Pred predicate)

Returns true if all elements satisfy the predicate.

any

bool any<Pred: bool(Element&)>(Pred predicate)

Returns true if any element satisfies the predicate.

bool any<T: Copyable, Pred: bool(T)>(Pred predicate)

Returns true if any element satisfies the predicate.

none

bool none<Pred: bool(Element&)>(Pred predicate)

Returns true if no element satisfies the predicate.

bool none<T: Copyable, Pred: bool(T)>(Pred predicate)

Returns true if no element satisfies the predicate.

struct SmallListIterator<Element, int N>: Iterator<Element&>

Iterates over the elements of a small list.

SmallListIterator

SmallListIterator(SmallList<Element, N>& list)

Initializes an iterator over the given list.

hasValue

bool hasValue()

Returns true if there are more elements.

value

Element& value()

Returns the current element.

increment

void increment()

Advances to the next element.

sum

Element sum()

Returns the sum of the remaining elements, or zero if there are none.

toList

List<Element> toList()

Collects the remaining elements into a list by copying them; only sound for Copyable elements.

operator==

bool operator==<T, int M, int N>(SmallList<T, M>& a, SmallList<T, N>& b)

Returns true if both lists have equal elements.