template<typename T>
slang::SmallVectorBase class

Base class for 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 that erases the stack size template parameter for use with generic code.

Derived classes

template<typename T, size_t N = detail::calculateDefaultSmallVectorElems<T>()>
class SmallVector
A concrete, sized version of the SmallVectorBase<T> template.

Public functions

iterator begin() constexpr noexcept
iterator end() constexpr noexcept
const_iterator begin() const constexpr noexcept
const_iterator end() const constexpr noexcept
reverse_iterator rbegin() constexpr noexcept
const_reverse_iterator rbegin() const constexpr noexcept
reverse_iterator rend() constexpr noexcept
const_reverse_iterator rend() const constexpr noexcept
const_reference front() const constexpr
const_reference back() const constexpr
reference front() constexpr
reference back() constexpr
pointer data() constexpr noexcept
const_pointer data() const constexpr noexcept
size_type size() const constexpr noexcept
size_type capacity() const constexpr noexcept
size_type max_size() const constexpr noexcept
bool empty() const constexpr noexcept
void reserve(size_type newCapacity)
Ensures that there is enough allocated memory in the array for at least size objects.
void resize(size_type newSize)
Resizes the array.
void resize(size_t newSize, const T& value)
Resizes the array.
void resize_for_overwrite(size_type newSize)
Resizes the array.
void clear() noexcept
Clears all elements but retain underlying storage.
void pop_back()
Removes the last element from the array. The array must not be empty!
void push_back(const T& item)
Adds an element to the end of the array.
void push_back(T&& item)
Adds an element to the end of the array.
template<typename... Args>
reference emplace_back(Args && ... args)
Constructs a new element at the end of the array.
template<std::input_iterator TIter>
void append(TIter first, TIter last)
Appends a range of elements to the end of the array.
template<std::ranges::input_range TContainer>
void append_range(const TContainer& container)
Appends a range of elements to the end of the array.
void append(size_type count, const T& value)
Appends count copies of value to the end of the array.
void assign(size_type count, const T& value)
Resets the contents of the array to be count copies of value.
template<std::input_iterator TIter>
void assign(TIter first, TIter last)
Resets the contents of the array to be the contents of the given range.
template<std::ranges::input_range TContainer>
void assign_range(const TContainer& container)
Resets the contents of the array to be the contents of the given range.
template<typename... Args>
iterator emplace(const_iterator pos, Args && ... args)
Constructs a new element at the specified position in the array.
iterator insert(const_iterator pos, const T& val)
Inserts the given value at the specified position in the array.
iterator insert(const_iterator pos, T&& val)
Inserts the given value at the specified position in the array.
template<std::ranges::input_range TContainer>
iterator insert_range(const_iterator pos, const TContainer& container)
Inserts a range of elements at the specified position in the array.
template<std::input_iterator TIter>
iterator insert(const_iterator pos, TIter first, TIter last)
Inserts a range of elements at the specified position in the array.
iterator insert(const_iterator pos, size_type count, const T& value)
Inserts count copies of value at the specified position in the array.
iterator erase(const_iterator pos)
Removes the elements at pos from the array.
iterator erase(const_iterator first, const_iterator last)
Removes all elements between first and last from the array.
void swap(SmallVectorBase& rhs)
Swaps the contents of rhs with this array.
std::span<T> copy(BumpAllocator& alloc) const
Creates a copy of the array using the given allocator.
std::span<ConstElem> ccopy(BumpAllocator& alloc) const
Creates a constant copy of the array using the given allocator.
reference operator[](size_type index) constexpr
const_reference operator[](size_type index) const constexpr
reference at(size_type index) constexpr
const_reference at(size_type index) const constexpr
bool isSmall() const constexpr noexcept
Indicates whether we are still "small", which means we are still on the stack.

Function documentation

template<typename T>
iterator slang::SmallVectorBase<T>::begin() constexpr noexcept

Returns an iterator to the beginning of the array.

template<typename T>
iterator slang::SmallVectorBase<T>::end() constexpr noexcept

Returns an iterator to the end of the array.

template<typename T>
const_iterator slang::SmallVectorBase<T>::begin() const constexpr noexcept

Returns an iterator to the beginning of the array.

template<typename T>
const_iterator slang::SmallVectorBase<T>::end() const constexpr noexcept

Returns an iterator to the end of the array.

template<typename T>
reverse_iterator slang::SmallVectorBase<T>::rbegin() constexpr noexcept

Returns a reverse iterator to the end of the array.

template<typename T>
const_reverse_iterator slang::SmallVectorBase<T>::rbegin() const constexpr noexcept

Returns a reverse iterator to the end of the array.

template<typename T>
reverse_iterator slang::SmallVectorBase<T>::rend() constexpr noexcept

Returns a reverse iterator to the end of the array.

template<typename T>
const_reverse_iterator slang::SmallVectorBase<T>::rend() const constexpr noexcept

Returns a reverse iterator to the end of the array.

template<typename T>
const_reference slang::SmallVectorBase<T>::front() const constexpr

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

template<typename T>
const_reference slang::SmallVectorBase<T>::back() const constexpr

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

template<typename T>
reference slang::SmallVectorBase<T>::front() constexpr

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

template<typename T>
reference slang::SmallVectorBase<T>::back() constexpr

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

template<typename T>
pointer slang::SmallVectorBase<T>::data() constexpr noexcept

Returns a pointer to the underlying array.

template<typename T>
const_pointer slang::SmallVectorBase<T>::data() const constexpr noexcept

Returns a pointer to the underlying array.

template<typename T>
size_type slang::SmallVectorBase<T>::size() const constexpr noexcept

Returns the number of elements in the array.

template<typename T>
size_type slang::SmallVectorBase<T>::capacity() const constexpr noexcept

Returns the number of elements that can be held in currently allocated storage.

template<typename T>
size_type slang::SmallVectorBase<T>::max_size() const constexpr noexcept

Returns the maximum number of elements that could ever fit in the array, assuming the system had enough memory to support it.

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

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

template<typename T>
void slang::SmallVectorBase<T>::resize(size_type newSize)

Resizes the array.

If larger than the current size, value constructs new elements to fill the gap. If smaller than the current size, the length is shrunk and elements are destructed.

template<typename T>
void slang::SmallVectorBase<T>::resize(size_t newSize, const T& value)

Resizes the array.

If larger than the current size, adds new elements as copies of value to fill the gap. If smaller than the current size, the length is shrunk and elements are destructed.

template<typename T>
void slang::SmallVectorBase<T>::resize_for_overwrite(size_type newSize)

Resizes the array.

If larger than the current size, default constructs new elements to fill the gap. If smaller than the current size, the length is shrunk and elements are destructed.

template<typename T>
std::span<ConstElem> slang::SmallVectorBase<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.

template<typename T>
reference slang::SmallVectorBase<T>::operator[](size_type index) constexpr

Returns the element at the given position in the array.

template<typename T>
const_reference slang::SmallVectorBase<T>::operator[](size_type index) const constexpr

Returns the element at the given position in the array.

template<typename T>
reference slang::SmallVectorBase<T>::at(size_type index) constexpr

Returns the element at the given position in the array.

template<typename T>
const_reference slang::SmallVectorBase<T>::at(size_type index) const constexpr

Returns the element at the given position in the array.