template<typename T>
slang::SmallVector class

Contents

SmallVector<T> - A fast growable array.

SmallVector is a vector-like growable array that allocates its first N elements on the stack. As long as you don't need more room than that, there are no heap allocations – otherwise we spill over into the heap. This is the base class for the actual sized implementation; it's split apart so that this one can be used in more general interfaces that don't care about the explicit stack size.

Derived classes

template<typename T, size_t N>
class SmallVectorSized

Public functions

auto begin() -> T*
auto end() -> T*
auto begin() const -> const T*
auto end() const -> const T*
auto cbegin() const -> const T*
auto cend() const -> const T*
auto front() const -> const T&
auto back() const -> const T&
auto front() -> T&
auto back() -> T&
auto data() const -> T* noexcept
auto size() const -> size_t noexcept
auto empty() const -> bool noexcept
void clear()
Clear all elements but retain underlying storage.
void pop()
Remove the last element from the array. Asserts if empty.
void append(const T& item)
Add an element to the end of the array.
template<typename Container>
void appendRange(const Container& container)
Add a range of elements to the end of the array.
void appendRange(const T* begin, const T* end)
Add a range of elements to the end of the array.
template<typename It>
void appendIterator(It begin, It end)
template<typename... Args>
void emplace(Args && ... args)
Construct a new element at the end of the array.
void extend(size_t size)
Adds size elements to the array (default constructed).
void reserve(size_t size)
Ensure that there is enough allocated memory in the array for at least size objects.
void resize(size_t size)
auto copy(BumpAllocator& alloc) const -> span<T>
Creates a copy of the array using the given allocator.
auto ccopy(BumpAllocator& alloc) const -> span<ConstElem>
auto isSmall() const -> bool
Indicates whether we are still "small", which means we are still on the stack.

Function documentation

template<typename T>
T* slang::SmallVector<T>::begin()

Returns a pointer / iterator to the beginning of the array.

template<typename T>
T* slang::SmallVector<T>::end()

Returns a pointer / iterator to the end of the array.

template<typename T>
const T* slang::SmallVector<T>::begin() const

Returns a pointer / iterator to the beginning of the array.

template<typename T>
const T* slang::SmallVector<T>::end() const

Returns a pointer / iterator to the end of the array.

template<typename T>
const T* slang::SmallVector<T>::cbegin() const

Returns a pointer / iterator to the beginning of the array.

template<typename T>
const T* slang::SmallVector<T>::cend() const

Returns a pointer / iterator to the end of the array.

template<typename T>
const T& slang::SmallVector<T>::front() const

Returns a reference to the first element in the array. The array must not be empty!

template<typename T>
const T& slang::SmallVector<T>::back() const

Returns a reference to the last element in the array. The array must not be empty!

template<typename T>
T& slang::SmallVector<T>::front()

Returns a reference to the first element in the array. The array must not be empty!

template<typename T>
T& slang::SmallVector<T>::back()

Returns a reference to the last element in the array. The array must not be empty!

template<typename T>
T* slang::SmallVector<T>::data() const noexcept

Returns a pointer to the underlying array.

template<typename T>
size_t slang::SmallVector<T>::size() const noexcept

Returns the number of elements in the array.

template<typename T>
bool slang::SmallVector<T>::empty() const noexcept

Returns true if the array is empty, and false if it has elements in it.

template<typename T> template<typename It>
void slang::SmallVector<T>::appendIterator(It begin, It end)

Add a range of elements to the end of the array, supporting simple forward iterators.

template<typename T>
void slang::SmallVector<T>::resize(size_t size)

Resize the array. If larger than the current size, default construct new elements to fill the gap. If smaller than the current size, the length is shrunk as if by repeatedly calling pop().

template<typename T>
span<ConstElem> slang::SmallVector<T>::ccopy(BumpAllocator& alloc) const

Creates a constant copy of the array using the given allocator. If the array holds pointers, const is added to the pointed-to type as well.