Classes | Public Types | Public Member Functions | Private Types | List of all members
blaze::SmallVector< T, N, A > Class Template Reference

Implementation of a dynamic vector with small vector optimization.The SmallVector class template is a hybrid data structure between a static array and a dynamic vector. It provides static, in-place memory for up to N elements of type T, but can grow beyond this size by allocating dynamic memory via its allocator of type A. More...

#include <SmallVector.h>

Inherits A.

Classes

struct  Uninitialized
 Definition of the nested auxiliary struct Uninitialized. More...
 

Public Types

using ElementType = T
 Type of the vector elements.
 
using Pointer = T *
 Pointer to a non-constant vector element.
 
using ConstPointer = const T *
 Pointer to a constant vector element.
 
using Reference = T &
 Reference to a non-constant vector element.
 
using ConstReference = const T &
 Reference to a constant vector element.
 
using Iterator = T *
 Iterator over non-constant elements.
 
using ConstIterator = const T *
 Iterator over constant elements.
 

Public Member Functions

template<typename U >
SmallVector< T, N, A > & operator= (initializer_list< U > list)
 List assignment to all vector elements. More...
 
Destructor
 ~SmallVector ()
 The destructor for DynamicVector.
 
Data access functions
Reference operator[] (size_t index) noexcept
 Subscript operator for the direct access to the vector elements. More...
 
ConstReference operator[] (size_t index) const noexcept
 Subscript operator for the direct access to the vector elements. More...
 
Reference at (size_t index)
 Checked access to the vector elements. More...
 
ConstReference at (size_t index) const
 Checked access to the vector elements. More...
 
Pointer data () noexcept
 Low-level data access to the vector elements. More...
 
ConstPointer data () const noexcept
 Low-level data access to the vector elements. More...
 
Iterator begin () noexcept
 Returns an iterator to the first element of the small vector. More...
 
ConstIterator begin () const noexcept
 Returns an iterator to the first element of the small vector. More...
 
ConstIterator cbegin () const noexcept
 Returns an iterator to the first element of the small vector. More...
 
Iterator end () noexcept
 Returns an iterator just past the last element of the small vector. More...
 
ConstIterator end () const noexcept
 Returns an iterator just past the last element of the small vector. More...
 
ConstIterator cend () const noexcept
 Returns an iterator just past the last element of the small vector. More...
 
Assignment operators
template<typename U >
SmallVectoroperator= (initializer_list< U > list)
 
SmallVectoroperator= (const SmallVector &rhs)
 Copy assignment operator for SmallVector. More...
 
SmallVectoroperator= (SmallVector &&rhs)
 Move assignment operator for SmallVector. More...
 

Private Types

enum  : size_t
 Adjustment of the size of the static storage.
 

Private Attributes

Member variables
byte_t v_ [NN]
 The static storage.
 
T * begin_
 Pointer to the beginning of the currently used storage.
 
T * end_
 Pointer to the end of the currently used storage.
 
T * final_
 Pointer to the very end of the currently used storage.
 

Constructors

 SmallVector (const A &alloc=A())
 The (default) constructor for SmallVector. More...
 
 SmallVector (size_t n, const A &alloc=A())
 Constructor for a vector of size n. No element initialization is performed! More...
 
 SmallVector (size_t n, const T &init, const A &alloc=A())
 Constructor for a vector of size n. More...
 
template<typename InputIt >
 SmallVector (InputIt first, InputIt last, const A &alloc=A())
 Constructor for a range of elements. More...
 
template<typename U >
 SmallVector (initializer_list< U > list, const A &alloc=A())
 List initialization of all vector elements. More...
 
 SmallVector (const SmallVector &sv)
 The copy constructor for SmallVector. More...
 
 SmallVector (SmallVector &&sv)
 The move constructor for SmallVector. More...
 
 SmallVector (size_t n, const A &alloc, Uninitialized)
 Auxiliary constructor for SmallVector. More...
 

Utility functions

bool empty () const noexcept
 Returns whether the vector is empty. More...
 
size_t size () const noexcept
 Returns the current size/dimension of the small vector. More...
 
size_t capacity () const noexcept
 Returns the maximum capacity of the small vector. More...
 
void clear ()
 Clearing the vector. More...
 
void resize (size_t n)
 Changing the size of the vector. More...
 
void resize (size_t n, const T &value)
 Changing the size of the vector. More...
 
void reserve (size_t n)
 Setting the minimum capacity of the vector. More...
 
void shrinkToFit ()
 Requesting the removal of unused capacity. More...
 
void pushBack (const T &value)
 Adding an element to the end of the small vector. More...
 
void pushBack (T &&value)
 Adding an element to the end of the small vector. More...
 
Iterator insert (Iterator pos, const T &value)
 Inserting an element at the specified position into the small vector. More...
 
Iterator insert (Iterator pos, T &&value)
 Inserting an element at the specified position into the small vector. More...
 
Iterator erase (Iterator pos)
 Erasing an element from the small vector. More...
 
Iterator erase (Iterator first, Iterator last)
 Erasing a range of elements from the small vector. More...
 
void swap (SmallVector &sv) noexcept(IsNothrowMoveConstructible< T >::value)
 Swapping the contents of two small vectors. More...
 
bool isDynamic () const noexcept
 Returns whether the small vector uses its dynamic storage. More...
 

Detailed Description

template<typename T, size_t N, typename A = std::allocator<T>>
class blaze::SmallVector< T, N, A >

Implementation of a dynamic vector with small vector optimization.

The SmallVector class template is a hybrid data structure between a static array and a dynamic vector. It provides static, in-place memory for up to N elements of type T, but can grow beyond this size by allocating dynamic memory via its allocator of type A.

Constructor & Destructor Documentation

◆ SmallVector() [1/8]

template<typename T , size_t N, typename A >
blaze::SmallVector< T, N, A >::SmallVector ( const A &  alloc = A())
inlineexplicit

The (default) constructor for SmallVector.

Parameters
allocAllocator for all memory allocations of this container.

◆ SmallVector() [2/8]

template<typename T , size_t N, typename A >
blaze::SmallVector< T, N, A >::SmallVector ( size_t  n,
const A &  alloc = A() 
)
inlineexplicit

Constructor for a vector of size n. No element initialization is performed!

Parameters
nThe initial size of the vector.
allocAllocator for all memory allocations of this container.

◆ SmallVector() [3/8]

template<typename T , size_t N, typename A >
blaze::SmallVector< T, N, A >::SmallVector ( size_t  n,
const T &  init,
const A &  alloc = A() 
)
inlineexplicit

Constructor for a vector of size n.

Parameters
nThe initial size of the vector.
initThe initial value of the vector elements.
allocAllocator for all memory allocations of this container.

All vector elements are initialized with the specified value.

◆ SmallVector() [4/8]

template<typename T , size_t N, typename A >
template<typename InputIt >
blaze::SmallVector< T, N, A >::SmallVector ( InputIt  first,
InputIt  last,
const A &  alloc = A() 
)
inlineexplicit

Constructor for a range of elements.

Parameters
firstIterator to the be first element of the input range.
lastIterator to the element one past the last element of the input range.
allocAllocator for all memory allocations of this container.

◆ SmallVector() [5/8]

template<typename T , size_t N, typename A >
template<typename U >
blaze::SmallVector< T, N, A >::SmallVector ( initializer_list< U >  list,
const A &  alloc = A() 
)
inlineexplicit

List initialization of all vector elements.

Parameters
listThe initializer list.
allocAllocator for all memory allocations of this container.

This constructor provides the option to explicitly initialize the elements of the small vector within a constructor call:

blaze::SmallVector<double,8UL> v1{ 4.2, 6.3, -1.2 };

The vector is sized according to the size of the initializer list and all its elements are copy initialized by the elements of the given initializer list.

◆ SmallVector() [6/8]

template<typename T , size_t N, typename A >
blaze::SmallVector< T, N, A >::SmallVector ( const SmallVector< T, N, A > &  sv)
inline

The copy constructor for SmallVector.

Parameters
svThe small vector to be copied.

◆ SmallVector() [7/8]

template<typename T , size_t N, typename A >
blaze::SmallVector< T, N, A >::SmallVector ( SmallVector< T, N, A > &&  sv)
inline

The move constructor for SmallVector.

Parameters
svThe small vector to be moved into this instance.

◆ SmallVector() [8/8]

template<typename T , size_t N, typename A >
blaze::SmallVector< T, N, A >::SmallVector ( size_t  n,
const A &  alloc,
Uninitialized   
)
inlineexplicitprivate

Auxiliary constructor for SmallVector.

Parameters
nThe initial size of the vector.
allocAllocator for all memory allocations of this container.

Member Function Documentation

◆ at() [1/2]

template<typename T , size_t N, typename A >
SmallVector< T, N, A >::Reference blaze::SmallVector< T, N, A >::at ( size_t  index)
inline

Checked access to the vector elements.

Parameters
indexAccess index. The index has to be in the range $[0..N-1]$.
Returns
Reference to the accessed value.
Exceptions
std::out_of_rangeInvalid small vector access index.

In contrast to the subscript operator this function always performs a check of the given access index.

◆ at() [2/2]

template<typename T , size_t N, typename A >
SmallVector< T, N, A >::ConstReference blaze::SmallVector< T, N, A >::at ( size_t  index) const
inline

Checked access to the vector elements.

Parameters
indexAccess index. The index has to be in the range $[0..N-1]$.
Returns
Reference to the accessed value.
Exceptions
std::out_of_rangeInvalid small vector access index.

In contrast to the subscript operator this function always performs a check of the given access index.

◆ begin() [1/2]

template<typename T , size_t N, typename A >
SmallVector< T, N, A >::Iterator blaze::SmallVector< T, N, A >::begin ( )
inlinenoexcept

Returns an iterator to the first element of the small vector.

Returns
Iterator to the first element of the small vector.

◆ begin() [2/2]

template<typename T , size_t N, typename A >
SmallVector< T, N, A >::ConstIterator blaze::SmallVector< T, N, A >::begin ( ) const
inlinenoexcept

Returns an iterator to the first element of the small vector.

Returns
Iterator to the first element of the small vector.

◆ capacity()

template<typename T , size_t N, typename A >
size_t blaze::SmallVector< T, N, A >::capacity ( ) const
inlinenoexcept

Returns the maximum capacity of the small vector.

Returns
The capacity of the small vector.

◆ cbegin()

template<typename T , size_t N, typename A >
SmallVector< T, N, A >::ConstIterator blaze::SmallVector< T, N, A >::cbegin ( ) const
inlinenoexcept

Returns an iterator to the first element of the small vector.

Returns
Iterator to the first element of the small vector.

◆ cend()

template<typename T , size_t N, typename A >
SmallVector< T, N, A >::ConstIterator blaze::SmallVector< T, N, A >::cend ( ) const
inlinenoexcept

Returns an iterator just past the last element of the small vector.

Returns
Iterator just past the last element of the small vector.

◆ clear()

template<typename T , size_t N, typename A >
void blaze::SmallVector< T, N, A >::clear ( )
inline

Clearing the vector.

Returns
void

After the clear() function, the size of the vector is 0.

◆ data() [1/2]

template<typename T , size_t N, typename A >
SmallVector< T, N, A >::Pointer blaze::SmallVector< T, N, A >::data ( )
inlinenoexcept

Low-level data access to the vector elements.

Returns
Pointer to the internal element storage.

This function returns a pointer to the internal storage of the small vector.

◆ data() [2/2]

template<typename T , size_t N, typename A >
SmallVector< T, N, A >::ConstPointer blaze::SmallVector< T, N, A >::data ( ) const
inlinenoexcept

Low-level data access to the vector elements.

Returns
Pointer to the internal element storage.

This function returns a pointer to the internal storage of the small vector.

◆ empty()

template<typename T , size_t N, typename A >
bool blaze::SmallVector< T, N, A >::empty ( ) const
inlinenoexcept

Returns whether the vector is empty.

Returns
true in case the vector is empty, false if not.

◆ end() [1/2]

template<typename T , size_t N, typename A >
SmallVector< T, N, A >::Iterator blaze::SmallVector< T, N, A >::end ( )
inlinenoexcept

Returns an iterator just past the last element of the small vector.

Returns
Iterator just past the last element of the small vector.

◆ end() [2/2]

template<typename T , size_t N, typename A >
SmallVector< T, N, A >::ConstIterator blaze::SmallVector< T, N, A >::end ( ) const
inlinenoexcept

Returns an iterator just past the last element of the small vector.

Returns
Iterator just past the last element of the small vector.

◆ erase() [1/2]

template<typename T , size_t N, typename A >
SmallVector< T, N, A >::Iterator blaze::SmallVector< T, N, A >::erase ( Iterator  pos)

Erasing an element from the small vector.

Parameters
posIterator to the element to be erased.
Returns
Iterator to the element after the erased element.

This function erases an element from the small vector.

◆ erase() [2/2]

template<typename T , size_t N, typename A >
SmallVector< T, N, A >::Iterator blaze::SmallVector< T, N, A >::erase ( Iterator  first,
Iterator  last 
)

Erasing a range of elements from the small vector.

Parameters
firstIterator to first element to be erased.
lastIterator just past the last element to be erased.
Returns
Iterator to the element after the erased element.

This function erases a range of elements from the small vector.

◆ insert() [1/2]

template<typename T , size_t N, typename A >
SmallVector< T, N, A >::Iterator blaze::SmallVector< T, N, A >::insert ( Iterator  pos,
const T &  value 
)

Inserting an element at the specified position into the small vector.

Parameters
posThe position of the new element.
valueThe value of the element to be inserted.
Returns
Reference to the inserted value.

◆ insert() [2/2]

template<typename T , size_t N, typename A >
SmallVector< T, N, A >::Iterator blaze::SmallVector< T, N, A >::insert ( Iterator  pos,
T &&  value 
)

Inserting an element at the specified position into the small vector.

Parameters
posThe position of the new element.
valueThe value of the element to be inserted.
Returns
Reference to the inserted value.

◆ isDynamic()

template<typename T , size_t N, typename A >
bool blaze::SmallVector< T, N, A >::isDynamic ( ) const
inlineprivatenoexcept

Returns whether the small vector uses its dynamic storage.

Returns
true in case the dynamic storage is in use, false if not.

◆ operator=() [1/3]

template<typename T , size_t N, typename A >
SmallVector< T, N, A > & blaze::SmallVector< T, N, A >::operator= ( const SmallVector< T, N, A > &  rhs)
inline

Copy assignment operator for SmallVector.

Parameters
rhsVector to be copied.
Returns
Reference to the assigned vector.

The vector is resized according to the given small vector and initialized as a copy of this vector.

◆ operator=() [2/3]

template<typename T , size_t N, typename A >
SmallVector< T, N, A > & blaze::SmallVector< T, N, A >::operator= ( SmallVector< T, N, A > &&  rhs)
inline

Move assignment operator for SmallVector.

Parameters
rhsThe vector to be moved into this instance.
Returns
Reference to the assigned vector.

◆ operator=() [3/3]

template<typename T, size_t N, typename A = std::allocator<T>>
template<typename U >
SmallVector<T,N,A>& blaze::SmallVector< T, N, A >::operator= ( initializer_list< U >  list)
inline

List assignment to all vector elements.

Parameters
listThe initializer list.

This assignment operator offers the option to directly assign to all elements of the small vector by means of an initializer list:

v = { 4.2, 6.3, -1.2 };

The vector is resized according to the size of the initializer list and all its elements are assigned the values from the given initializer list.

◆ operator[]() [1/2]

template<typename T , size_t N, typename A >
SmallVector< T, N, A >::Reference blaze::SmallVector< T, N, A >::operator[] ( size_t  index)
inlinenoexcept

Subscript operator for the direct access to the vector elements.

Parameters
indexAccess index. The index has to be in the range $[0..N-1]$.
Returns
Reference to the accessed value.

This function only performs an index check in case BLAZE_USER_ASSERT() is active. In contrast, the at() function is guaranteed to perform a check of the given access index.

◆ operator[]() [2/2]

template<typename T , size_t N, typename A >
SmallVector< T, N, A >::ConstReference blaze::SmallVector< T, N, A >::operator[] ( size_t  index) const
inlinenoexcept

Subscript operator for the direct access to the vector elements.

Parameters
indexAccess index. The index has to be in the range $[0..N-1]$.
Returns
Reference-to-const to the accessed value.

This function only performs an index check in case BLAZE_USER_ASSERT() is active. In contrast, the at() function is guaranteed to perform a check of the given access index.

◆ pushBack() [1/2]

template<typename T , size_t N, typename A >
void blaze::SmallVector< T, N, A >::pushBack ( const T &  value)

Adding an element to the end of the small vector.

Parameters
valueThe element to be added to the end of the small vector.
Returns
void

◆ pushBack() [2/2]

template<typename T , size_t N, typename A >
void blaze::SmallVector< T, N, A >::pushBack ( T &&  value)

Adding an element to the end of the small vector.

Parameters
valueThe element to be added to the end of the small vector.
Returns
void

◆ reserve()

template<typename T , size_t N, typename A >
void blaze::SmallVector< T, N, A >::reserve ( size_t  n)

Setting the minimum capacity of the vector.

Parameters
nThe new minimum capacity of the vector.
Returns
void

This function increases the capacity of the vector to at least n elements. The current values of the vector elements are preserved.

◆ resize() [1/2]

template<typename T , size_t N, typename A >
void blaze::SmallVector< T, N, A >::resize ( size_t  n)

Changing the size of the vector.

Parameters
nThe new size of the vector.
Returns
void

This function resizes the vector using the given size to n. During this operation, new dynamic memory may be allocated in case the capacity of the vector is too small. New vector elements are not initialized!

◆ resize() [2/2]

template<typename T , size_t N, typename A >
void blaze::SmallVector< T, N, A >::resize ( size_t  n,
const T &  value 
)

Changing the size of the vector.

Parameters
nThe new size of the vector.
valueThe initial value of new vector elements.
Returns
void

This function resizes the vector using the given size to n. During this operation, new dynamic memory may be allocated in case the capacity of the vector is too small. New vector elements are initialized to value!

◆ shrinkToFit()

template<typename T , size_t N, typename A >
void blaze::SmallVector< T, N, A >::shrinkToFit ( )

Requesting the removal of unused capacity.

Returns
void

This function minimizes the capacity of the vector by removing unused capacity. Please note that in case a reallocation occurs, all iterators (including end() iterators), all pointers and references to elements of this vector are invalidated.

◆ size()

template<typename T , size_t N, typename A >
size_t blaze::SmallVector< T, N, A >::size ( ) const
inlinenoexcept

Returns the current size/dimension of the small vector.

Returns
The current size of the small vector.

◆ swap()

template<typename T , size_t N, typename A >
void blaze::SmallVector< T, N, A >::swap ( SmallVector< T, N, A > &  sv)
noexcept

Swapping the contents of two small vectors.

Parameters
svThe small vector to be swapped.
Returns
void

This function swaps the contents of two small vectors. Please note that this function is only guaranteed to not throw an exception if the move constructor of the underlying data type T is guaranteed to be noexcept.


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