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

Implementation of a dynamic array with small array optimization. More...

#include <SmallArray.h>

Inherits SmallArrayData< T, N >, and std::allocator< T >.

Classes

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

Public Types

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

Public Member Functions

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

Private Attributes

elements
 STL member.
 
Member variables
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

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

Utility functions

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

Detailed Description

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

Implementation of a dynamic array with small array optimization.

The SmallArray class template is a hybrid data structure between a static array and a dynamic array. 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

◆ SmallArray() [1/8]

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

The (default) constructor for SmallArray.

Parameters
allocAllocator for all memory allocations of this container.

◆ SmallArray() [2/8]

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

Constructor for an array of size n. No element initialization is performed!

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

◆ SmallArray() [3/8]

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

Constructor for an array of size n.

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

All array elements are initialized with the specified value.

◆ SmallArray() [4/8]

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

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.

◆ SmallArray() [5/8]

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

List initialization of all array 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 array within a constructor call:

blaze::SmallArray<double,8UL> v1{ 4.2, 6.3, -1.2 };
Implementation of a dynamic array with small array optimization.
Definition: SmallArray.h:84

The array 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.

◆ SmallArray() [6/8]

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

The copy constructor for SmallArray.

Parameters
saThe small array to be copied.

◆ SmallArray() [7/8]

template<typename T , size_t N, typename A >
blaze::SmallArray< T, N, A >::SmallArray ( SmallArray< T, N, A > &&  sa)
inline

The move constructor for SmallArray.

Parameters
saThe small array to be moved into this instance.

◆ SmallArray() [8/8]

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

Auxiliary constructor for SmallArray.

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

Member Function Documentation

◆ at() [1/2]

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

Checked access to the array 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 array 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 >
SmallArray< T, N, A >::ConstReference blaze::SmallArray< T, N, A >::at ( size_t  index) const
inline

Checked access to the array 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 array 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 >
SmallArray< T, N, A >::ConstIterator blaze::SmallArray< T, N, A >::begin
inlinenoexcept

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

Returns
Iterator to the first element of the small array.

◆ begin() [2/2]

template<typename T , size_t N, typename A >
SmallArray< T, N, A >::Iterator blaze::SmallArray< T, N, A >::begin
inlinenoexcept

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

Returns
Iterator to the first element of the small array.

◆ capacity()

template<typename T , size_t N, typename A >
size_t blaze::SmallArray< T, N, A >::capacity
inlinenoexcept

Returns the maximum capacity of the small array.

Returns
The capacity of the small array.

◆ cbegin()

template<typename T , size_t N, typename A >
SmallArray< T, N, A >::ConstIterator blaze::SmallArray< T, N, A >::cbegin
inlinenoexcept

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

Returns
Iterator to the first element of the small array.

◆ cend()

template<typename T , size_t N, typename A >
SmallArray< T, N, A >::ConstIterator blaze::SmallArray< T, N, A >::cend
inlinenoexcept

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

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

◆ clear()

template<typename T , size_t N, typename A >
void blaze::SmallArray< T, N, A >::clear
inline

Clearing the array.

Returns
void

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

◆ data() [1/2]

template<typename T , size_t N, typename A >
SmallArray< T, N, A >::ConstPointer blaze::SmallArray< T, N, A >::data
inlinenoexcept

Low-level data access to the array elements.

Returns
Pointer to the internal element storage.

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

◆ data() [2/2]

template<typename T , size_t N, typename A >
SmallArray< T, N, A >::Pointer blaze::SmallArray< T, N, A >::data
inlinenoexcept

Low-level data access to the array elements.

Returns
Pointer to the internal element storage.

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

◆ empty()

template<typename T , size_t N, typename A >
bool blaze::SmallArray< T, N, A >::empty
inlinenoexcept

Returns whether the array is empty.

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

◆ end() [1/2]

template<typename T , size_t N, typename A >
SmallArray< T, N, A >::ConstIterator blaze::SmallArray< T, N, A >::end
inlinenoexcept

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

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

◆ end() [2/2]

template<typename T , size_t N, typename A >
SmallArray< T, N, A >::Iterator blaze::SmallArray< T, N, A >::end
inlinenoexcept

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

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

◆ erase() [1/2]

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

Erasing a range of elements from the small array.

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 array.

◆ erase() [2/2]

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

Erasing an element from the small array.

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 array.

◆ insert() [1/2]

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

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

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 >
SmallArray< T, N, A >::Iterator blaze::SmallArray< T, N, A >::insert ( Iterator  pos,
T &&  value 
)

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

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::SmallArray< T, N, A >::isDynamic
inlineprivatenoexcept

Returns whether the small array 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 >
SmallArray< T, N, A > & blaze::SmallArray< T, N, A >::operator= ( const SmallArray< T, N, A > &  rhs)
inline

Copy assignment operator for SmallArray.

Parameters
rhsArray to be copied.
Returns
Reference to the assigned array.

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

◆ operator=() [2/3]

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

List assignment to all array elements.

Parameters
listThe initializer list.

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

v = { 4.2, 6.3, -1.2 };

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

◆ operator=() [3/3]

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

Move assignment operator for SmallArray.

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

◆ operator[]() [1/2]

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

Subscript operator for the direct access to the array 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.

◆ operator[]() [2/2]

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

Subscript operator for the direct access to the array 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.

◆ pushBack() [1/2]

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

Adding an element to the end of the small array.

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

◆ pushBack() [2/2]

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

Adding an element to the end of the small array.

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

◆ reserve()

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

Setting the minimum capacity of the array.

Parameters
nThe new minimum capacity of the array.
Returns
void

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

◆ resize() [1/2]

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

Changing the size of the array.

Parameters
nThe new size of the array.
Returns
void

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

◆ resize() [2/2]

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

Changing the size of the array.

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

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

◆ shrinkToFit()

template<typename T , size_t N, typename A >
void blaze::SmallArray< T, N, A >::shrinkToFit

Requesting the removal of unused capacity.

Returns
void

This function minimizes the capacity of the array 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 array are invalidated.

◆ size()

template<typename T , size_t N, typename A >
size_t blaze::SmallArray< T, N, A >::size
inlinenoexcept

Returns the current size/dimension of the small array.

Returns
The current size of the small array.

◆ swap()

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

Swapping the contents of two small arrays.

Parameters
saThe small array to be swapped.
Returns
void

This function swaps the contents of two small arrays. 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: