Sane C++ Libraries
C++ Platform Abstraction Libraries
SC::SmallVector< T, N > Struct Template Reference

A Vector that can hold up to N elements inline and > N on heap. More...

#include <SmallVector.h>

Inheritance diagram for SC::SmallVector< T, N >:
SC::Vector< T >

Public Member Functions

 SmallVector (SmallVector &&other)
 
 SmallVector (const SmallVector &other)
 
SmallVectoroperator= (SmallVector &&other)
 
SmallVectoroperator= (const SmallVector &other)
 
 SmallVector (Vector< T > &&other)
 
 SmallVector (const Vector< T > &other)
 
SmallVectoroperator= (Vector< T > &&other)
 
SmallVectoroperator= (const Vector< T > &other)
 
- Public Member Functions inherited from SC::Vector< T >
 Vector ()
 Constructs an empty Vector. More...
 
 Vector (std::initializer_list< T > list)
 Constructs a Vector from an initializer list. More...
 
 ~Vector ()
 Destroys the Vector, releasing allocated memory. More...
 
 Vector (const Vector &other)
 Copies vector into this vector. More...
 
 Vector (Vector &&other) noexcept
 Moves vector contents into this vector. More...
 
Vectoroperator= (Vector &&other)
 Move assigns another vector to this one. More...
 
Vectoroperator= (const Vector &other)
 Copy assigns another vector to this one. More...
 
Span< const T > toSpanConst () const SC_LANGUAGE_LIFETIME_BOUND
 Returns a Span wrapping the entire of current vector. More...
 
Span< T > toSpan () SC_LANGUAGE_LIFETIME_BOUND
 Returns a Span wrapping the entire of current vector. More...
 
T & operator[] (size_t index) SC_LANGUAGE_LIFETIME_BOUND
 Access item at index. More...
 
const T & operator[] (size_t index) const SC_LANGUAGE_LIFETIME_BOUND
 Access item at index. More...
 
bool push_front (const T &element)
 Copies an element in front of the Vector, at position 0. More...
 
bool push_front (T &&element)
 Moves an element in front of the Vector, at position 0. More...
 
bool push_back (const T &element)
 Appends an element copying it at the end of the Vector. More...
 
bool push_back (T &&element)
 Appends an element moving it at the end of the Vector. More...
 
bool pop_back ()
 Removes the last element of the vector. More...
 
bool pop_front ()
 Removes the first element of the vector. More...
 
T & front () SC_LANGUAGE_LIFETIME_BOUND
 Access the first element of the Vector. More...
 
const T & front () const SC_LANGUAGE_LIFETIME_BOUND
 Access the first element of the Vector. More...
 
T & back () SC_LANGUAGE_LIFETIME_BOUND
 Access the last element of the Vector. More...
 
const T & back () const SC_LANGUAGE_LIFETIME_BOUND
 Access the last element of the Vector. More...
 
bool reserve (size_t newCapacity)
 Reserves memory for newCapacity elements, allocating memory if necessary. More...
 
bool resize (size_t newSize, const T &value=T())
 Resizes this vector to newSize, preserving existing elements. More...
 
bool resizeWithoutInitializing (size_t newSize)
 Resizes this vector to newSize, preserving existing elements. More...
 
void clear ()
 Removes all elements from container, calling destructor for each of them. More...
 
void clearWithoutInitializing ()
 Sets size() to zero, without calling destructor on elements. More...
 
bool shrink_to_fit ()
 Reallocates the vector so that size() == capacity(). More...
 
bool isEmpty () const
 Check if the vector is empty. More...
 
size_t size () const
 Gets size of the vector. More...
 
size_t capacity () const
 Gets capacity of the vector. More...
 
T * begin () SC_LANGUAGE_LIFETIME_BOUND
 Gets pointer to first element of the vector. More...
 
const T * begin () const SC_LANGUAGE_LIFETIME_BOUND
 Gets pointer to first element of the vector. More...
 
T * end () SC_LANGUAGE_LIFETIME_BOUND
 Gets pointer to one after last element of the vector. More...
 
const T * end () const SC_LANGUAGE_LIFETIME_BOUND
 Gets pointer to one after last element of the vector. More...
 
T * data () SC_LANGUAGE_LIFETIME_BOUND
 Gets pointer to first element of the vector. More...
 
const T * data () const SC_LANGUAGE_LIFETIME_BOUND
 Gets pointer to first element of the vector. More...
 
bool insert (size_t idx, Span< const T > data)
 Inserts a range of items copying them at given index. More...
 
bool append (Span< const T > data)
 Appends a range of items copying them at the end of vector. More...
 
template<typename U >
bool append (Span< const U > src)
 Appends a range of items copying them at the end of vector. More...
 
template<typename U >
bool appendMove (U &&src)
 Appends another vector moving its contents at the end of vector. More...
 
template<typename U >
bool contains (const U &value, size_t *foundIndex=nullptr) const
 Check if the current vector contains a given value. More...
 
template<typename Lambda >
bool find (Lambda &&lambda, size_t *foundIndex=nullptr) const
 Finds the first item in vector matching criteria given by the lambda. More...
 
bool removeAt (size_t index)
 Removes an item at a given index. More...
 
template<typename Lambda >
bool removeAll (Lambda &&criteria)
 Removes all items matching criteria given by Lambda. More...
 
template<typename U >
bool remove (const U &value)
 Removes all values equal to value More...
 

Public Attributes

Array< T, N > buffer
 

Additional Inherited Members

- Protected Types inherited from SC::Vector< T >
using Operations = SegmentOperations< VectorAllocator, T >
 
- Protected Member Functions inherited from SC::Vector< T >
SegmentItems< T > * getSegmentItems () const
 
- Protected Attributes inherited from SC::Vector< T >
T * items
 

Detailed Description

template<typename T, int N>
struct SC::SmallVector< T, N >

A Vector that can hold up to N elements inline and > N on heap.

Template Parameters
TType of single vector element
NNumber of elements kept inline to avoid heap allocation

SC::SmallVector is like SC::Vector but it will do heap allocation once more than N elements are needed.
When the size() becomes less than N the container will switch back using memory coming from inline storage.

Note
SC::SmallVector derives from SC::Vector and it can be passed everywhere a reference to SC::Vector is needed. It can be used to get rid of unnecessary allocations where the upper bound of required elements is known or it can be predicted.

The documentation for this struct was generated from the following file: