#include <slang/util/SafeIndexedVector.h>
template<typename T, typename Index>
SafeIndexedVector class
SafeIndexedVector - a flat random-access container that uses a strongly typed integer type for indexing, so that clients can store indices without chance of mistaking them for some other value.
Indices are never invalidated until they are removed from the index, at which point they are placed on a freelist and potentially reused.
The index uses a vector internally for managing storage and therefore has the same performance characteristics when adding new elements and there are no open slots in the freelist.
Note that index zero is always reserved as an invalid sentinel value. The Index type must be explicitly convertible to and from size_t.
T should be default-constructible, and its default constructed state should represent an invalid / empty value.
Public functions
- auto add(const T& item) -> Index
- Add a new item to the vector by copying and return an Index to its location.
- auto add(T&& item) -> Index
- Add a new item to the vector by moving and return an Index to its location.
-
template<typename... Args>auto emplace(Args && ... args) -> Index
- Construct a new item in the vector and return an Index to its location.
- void remove(Index index)
- Remove the item at the given index.
- void clear()
- Removes all items from the vector.
-
auto size() const -> size_
t - auto empty() const -> bool
Function documentation
template<typename T, typename Index>
void slang:: SafeIndexedVector<T, Index>:: remove(Index index)
Remove the item at the given index.
This operation is O(1) because the removed index is added to a free list instead of moving other elements around.
template<typename T, typename Index>
bool slang:: SafeIndexedVector<T, Index>:: empty() const
Returns | true if the vector is empty, and false if it has elements in it. |
---|