C4 Engine
C4 Engine API Documentation

class List

Defined in:  TSList.h
The List class encapsulates a doubly-linked list.

template <class type> class List : public ListBase

Member Functions
List::GetFirstListElement Returns the first element in a list.
List::GetLastListElement Returns the last element in a list.
List::Member Returns a boolean value indicating whether a particular object is a member of a list.
List::Empty Returns a boolean value indicating whether a list is empty.
List::GetListElementCount Returns the number of elements in a list.
List::PrependListElement Adds an object to the beginning of a list.
List::AppendListElement Adds an object to the end of a list.
List::InsertListElementBefore Inserts an object before an existing element of a list.
List::InsertListElementAfter Inserts an object after an existing element of a list.
List::RemoveListElement Removes a particular element from a list.
List::RemoveAllListElements Removes all elements from a list.
List::PurgeList Deletes all elements in a list.
Template Parameters
type The type of the class that can be stored in the list. The class specified by this parameter should inherit directly from the ListElement class using the same template parameter.


The List class template is a container used to store a homogeneous doubly-linked list of objects. The class type of objects that are to be stored in the list must be a subclass of the ListElement class template using the same template parameter as the List container. A particular object can be a member of only one list at a time.

Upon construction, a List object is empty. When a List object is destroyed, all of the members of the list are also destroyed. To avoid deleting the members of a list when a List object is destroyed, first call the List::RemoveAllListElements function to remove all of the list's members.

It is possible to iterate over the elements of a list using a range-based for loop. This is illustrated by the following code, where list is a variable of type List<type>.
for (type *element : list)
Overloaded Operators
type *operator [](machine index) const; Returns the element of a list whose zero-based index is index. If index is greater than or equal to the number of elements in the list, then the return value is nullptr.
Base Classes
ListBase Used internally to encapsulate common functionality that is independent of the template parameter.
See Also