List<T>
cer::List<T>
represents a dynamically-sized array, just like std::vector<T>
.
It ensures that its items are laid out in contiguous storage.
The signature of List
is as follows:
List
offers a similar API to std::vector
and is supported by <algorithm>
functions.
There are some differences however.
Operations
Construction
Adding elements
Adding elements to the end of the list is done by using the add()
method, instead of push_back()
.
Appending other lists and ranges is done by using the append()
method.
Finding elements
For convenience, a List
provides quick access methods, so that you don’t have to work with std::find()
and iterators.
Instead, these methods return a simple boolean and Option
values.
Small buffer optimization
List
implements a small buffer optimization, which means that it’s able to store an arbitrary
number of elements on the stack instead of on the heap.
The capacity for this small buffer is specified using the second template parameter (InlineCapacity
),
and is expected to be a positive int
.
This allows you to avoid heap allocations when you can estimate the number of items that will be in stored in a list, in the average case.
Calling clear()
will not move the storage back to the stack.