Get Involved


A TypedList object contains a list of typed items. Internally, a TypedList maintains a linked list of chunks, with the items stored contiguously in memory within each chunk. TypedList offers an alternative to Array that can grow to an arbitrary number of items without ever reallocating memory. Once an item is added to a TypedList, the item's address never changes. The items are destructed and freed when the TypedList is destroyed.

Header File

#include <ply-runtime/container/TypedList.h>


  TypedList::TypedList() [code]

Constructs an empty TypedList.

TypedList<String> list;
  TypedList::TypedList(TypedList&& other) [code]

Move constructor. other is left in an unusable state and cannot be modified after this operation.

TypedList<String> arr = std::move(other);
TypedList::~TypedList() [code]

Destructor. Destructs all items and frees the memory associated with the TypedList.


void TypedList::operator=(TypedList&& other) [code]

Move assignment operator. other is left in an unusable state and cannot be modified after this operation.

arr = std::move(other);


 bool TypedList::isEmpty() const [code]

Returns true if the list is empty.


 ArrayView<T> TypedList::beginWriteViewNoConstruct() [code]

Returns an ArrayView of allocated but uninitialized items. The returned ArrayView always contains at least one item. The caller is meant to construct some number of items, then call endWrite.

ArrayView<String> view = list.beginWriteViewNoConstruct();
for (u32 i = 0; i < view.numItems; i++) {
    new (&view[i]) String{String::from(i)};
 T* TypedList::beginWriteNoConstruct() [code]

Returns a pointer to a single uninitialized item. The caller is meant to construct this item, then call endWrite.

String* item = list.beginWriteNoConstruct();
new (item) String;
 void TypedList::endWrite(u32 numItems = 1) [code]

Must be called after beginWriteViewNoConstruct or beginWriteNoConstruct after constructing some number of items. Advances the write position and makes the newly constructed items available for read.

 T& TypedList::append(const T& item) [code]
 T& TypedList::append(T&& item) [code]
 template <typename Args>
T& TypedList::append(Args&& args) [code]

Appends a single item to the list and returns a reference to it. The arguments are forwarded directly to the item's constructor. The returned reference remains valid until the TypedList is destroyed or moveToArray is called.

TypedList<String> list;
 void TypedList::clear() [code]

Destructs all items in the list and frees any associated memory. The TypedList is left in an empty state.


 Array<T> TypedList::moveToArray() [code]

Converts the list of items to an Array. When the number of items fits in a single chunk, the chunk is truncated and directly adopted by the Array, avoiding unnecessary memory reallocation or copying. The TypedList is left in an unusable state and cannot be modified after this operation.

TypedList<String> list;
Array<String> arr = list.moveToArray();


 TypedListIterator<T> TypedList::begin() const [code]
 TypedListIterator<T> TypedList::end() const [code]

Required functions to support range-for syntax. Allows you to iterate over all the items in the list.

for (const T& item : list) {