nfx-containers 0.6.0
Modern C++20 header-only library providing high-performance hash containers with Robin Hood and perfect hashing
Loading...
Searching...
No Matches
nfx::containers::StackVector< T, N > Class Template Referencefinal

Vector with stack storage optimization. More...

#include <nfx/containers/StackVector.h>

Public Types

using value_type = T
 Type alias for element type.
using size_type = std::size_t
 Type alias for size type.
using difference_type = std::ptrdiff_t
 Type alias for difference type.
using reference = T&
 Type alias for reference to element.
using const_reference = const T&
 Type alias for const reference to element.
using pointer = T*
 Type alias for pointer to element.
using const_pointer = const T*
 Type alias for const pointer to element.

Public Member Functions

 StackVector () noexcept
 Default constructor.
 StackVector (std::initializer_list< T > init)
 Construct from initializer list.
 StackVector (const StackVector &other)
 Copy constructor.
 StackVector (StackVector &&other) noexcept
 Move constructor.
 ~StackVector () noexcept
 Destructor.
StackVectoroperator= (const StackVector &other)
 Copy assignment operator.
StackVectoroperator= (StackVector &&other) noexcept
 Move assignment operator.
bool operator== (const StackVector &other) const noexcept
 Equality comparison operator.
bool operator!= (const StackVector &other) const noexcept
 Inequality comparison operator.
void push_back (const T &value)
 Add element to end (copy).
void push_back (T &&value)
 Add element to end (move).
template<typename... Args>
void emplace_back (Args &&... args)
 Construct element in-place at end.
reference operator[] (size_type pos) noexcept
 Access element at position (no bounds checking).
const_reference operator[] (size_type pos) const noexcept
 Access element at position (no bounds checking) const.
reference at (size_type pos)
 Access element at position (with bounds checking).
const_reference at (size_type pos) const
 Access element at position (with bounds checking) const.
reference back () noexcept
 Access last element.
const_reference back () const noexcept
 Access last element const.
reference front () noexcept
 Access first element.
const_reference front () const noexcept
 Access first element const.
StackVector< T, N >::size_type size () const noexcept
 Get number of elements.
bool isEmpty () const noexcept
 Check if container is empty.
size_type capacity () const noexcept
 Get current capacity.
void resize (size_type count)
 Resize container to specified size.
void resize (size_type count, const T &value)
 Resize container to specified size with default value.
void reserve (size_type newCapacity)
 Reserve storage for at least specified capacity.
pointer data () noexcept
 Get pointer to underlying data.
const_pointer data () const noexcept
 Get const pointer to underlying data.
pointer begin () noexcept
 Get iterator to beginning.
const_pointer begin () const noexcept
 Get const iterator to beginning.
pointer end () noexcept
 Get iterator to end.
const_pointer end () const noexcept
 Get const iterator to end.
const_pointer cbegin () const noexcept
 Get const iterator to beginning.
const_pointer cend () const noexcept
 Get const iterator to end.
void clear () noexcept
 Clear all elements.
void pop_back () noexcept
 Remove last element.

Detailed Description

template<typename T, std::size_t N = 8>
class nfx::containers::StackVector< T, N >

Vector with stack storage optimization.

Template Parameters
TElement type
NMaximum number of elements to store on stack before heap allocation

Stores up to N elements on the stack for optimal cache locality and zero heap allocations. Automatically transitions to heap storage when size exceeds N.

Definition at line 54 of file StackVector.h.

Member Typedef Documentation

◆ const_pointer

template<typename T, std::size_t N = 8>
using nfx::containers::StackVector< T, N >::const_pointer = const T*

Type alias for const pointer to element.

Definition at line 80 of file StackVector.h.

◆ const_reference

template<typename T, std::size_t N = 8>
using nfx::containers::StackVector< T, N >::const_reference = const T&

Type alias for const reference to element.

Definition at line 74 of file StackVector.h.

◆ difference_type

template<typename T, std::size_t N = 8>
using nfx::containers::StackVector< T, N >::difference_type = std::ptrdiff_t

Type alias for difference type.

Definition at line 68 of file StackVector.h.

◆ pointer

template<typename T, std::size_t N = 8>
using nfx::containers::StackVector< T, N >::pointer = T*

Type alias for pointer to element.

Definition at line 77 of file StackVector.h.

◆ reference

template<typename T, std::size_t N = 8>
using nfx::containers::StackVector< T, N >::reference = T&

Type alias for reference to element.

Definition at line 71 of file StackVector.h.

◆ size_type

template<typename T, std::size_t N = 8>
using nfx::containers::StackVector< T, N >::size_type = std::size_t

Type alias for size type.

Definition at line 65 of file StackVector.h.

◆ value_type

template<typename T, std::size_t N = 8>
using nfx::containers::StackVector< T, N >::value_type = T

Type alias for element type.

Definition at line 62 of file StackVector.h.

Constructor & Destructor Documentation

◆ StackVector() [1/3]

template<typename T, std::size_t N = 8>
nfx::containers::StackVector< T, N >::StackVector ( std::initializer_list< T > init)
inline

Construct from initializer list.

Parameters
initInitializer list of elements

◆ StackVector() [2/3]

template<typename T, std::size_t N = 8>
nfx::containers::StackVector< T, N >::StackVector ( const StackVector< T, N > & other)
inline

Copy constructor.

Parameters
otherThe StackVector to copy from

◆ StackVector() [3/3]

template<typename T, std::size_t N = 8>
nfx::containers::StackVector< T, N >::StackVector ( StackVector< T, N > && other)
inlinenoexcept

Move constructor.

Parameters
otherThe StackVector to move from

Member Function Documentation

◆ at() [1/2]

template<typename T, std::size_t N = 8>
reference nfx::containers::StackVector< T, N >::at ( size_type pos)
inline

Access element at position (with bounds checking).

Parameters
posPosition of element
Returns
Reference to element
Exceptions
std::out_of_rangeif pos >= size()

◆ at() [2/2]

template<typename T, std::size_t N = 8>
const_reference nfx::containers::StackVector< T, N >::at ( size_type pos) const
inline

Access element at position (with bounds checking) const.

Parameters
posPosition of element
Returns
Const reference to element
Exceptions
std::out_of_rangeif pos >= size()

◆ back() [1/2]

template<typename T, std::size_t N = 8>
const_reference nfx::containers::StackVector< T, N >::back ( ) const
inlinenoexcept

Access last element const.

Returns
Const reference to last element

◆ back() [2/2]

template<typename T, std::size_t N = 8>
reference nfx::containers::StackVector< T, N >::back ( )
inlinenoexcept

Access last element.

Returns
Reference to last element

◆ begin() [1/2]

template<typename T, std::size_t N = 8>
const_pointer nfx::containers::StackVector< T, N >::begin ( ) const
inlinenoexcept

Get const iterator to beginning.

Returns
Const iterator to first element

◆ begin() [2/2]

template<typename T, std::size_t N = 8>
pointer nfx::containers::StackVector< T, N >::begin ( )
inlinenoexcept

Get iterator to beginning.

Returns
Iterator to first element

◆ capacity()

template<typename T, std::size_t N = 8>
size_type nfx::containers::StackVector< T, N >::capacity ( ) const
inlinenoexcept

Get current capacity.

Returns
Number of elements that can be held without reallocation

◆ cbegin()

template<typename T, std::size_t N = 8>
const_pointer nfx::containers::StackVector< T, N >::cbegin ( ) const
inlinenoexcept

Get const iterator to beginning.

Returns
Const iterator to first element

◆ cend()

template<typename T, std::size_t N = 8>
const_pointer nfx::containers::StackVector< T, N >::cend ( ) const
inlinenoexcept

Get const iterator to end.

Returns
Const iterator to one past last element

◆ data() [1/2]

template<typename T, std::size_t N = 8>
const_pointer nfx::containers::StackVector< T, N >::data ( ) const
inlinenoexcept

Get const pointer to underlying data.

Returns
Const pointer to first element

◆ data() [2/2]

template<typename T, std::size_t N = 8>
pointer nfx::containers::StackVector< T, N >::data ( )
inlinenoexcept

Get pointer to underlying data.

Returns
Pointer to first element

◆ emplace_back()

template<typename T, std::size_t N = 8>
template<typename... Args>
void nfx::containers::StackVector< T, N >::emplace_back ( Args &&... args)
inline

Construct element in-place at end.

Template Parameters
ArgsTypes of arguments to forward to constructor
Parameters
argsArguments to forward to element constructor

◆ end() [1/2]

template<typename T, std::size_t N = 8>
const_pointer nfx::containers::StackVector< T, N >::end ( ) const
inlinenoexcept

Get const iterator to end.

Returns
Const iterator to one past last element

◆ end() [2/2]

template<typename T, std::size_t N = 8>
pointer nfx::containers::StackVector< T, N >::end ( )
inlinenoexcept

Get iterator to end.

Returns
Iterator to one past last element

◆ front() [1/2]

template<typename T, std::size_t N = 8>
const_reference nfx::containers::StackVector< T, N >::front ( ) const
inlinenoexcept

Access first element const.

Returns
Const reference to first element

◆ front() [2/2]

template<typename T, std::size_t N = 8>
reference nfx::containers::StackVector< T, N >::front ( )
inlinenoexcept

Access first element.

Returns
Reference to first element

◆ isEmpty()

template<typename T, std::size_t N = 8>
bool nfx::containers::StackVector< T, N >::isEmpty ( ) const
inlinenoexcept

Check if container is empty.

Returns
true if size() == 0, false otherwise

◆ operator!=()

template<typename T, std::size_t N = 8>
bool nfx::containers::StackVector< T, N >::operator!= ( const StackVector< T, N > & other) const
inlinenoexcept

Inequality comparison operator.

Parameters
otherThe StackVector to compare with
Returns
true if not equal, false otherwise

◆ operator=() [1/2]

template<typename T, std::size_t N = 8>
StackVector & nfx::containers::StackVector< T, N >::operator= ( const StackVector< T, N > & other)
inline

Copy assignment operator.

Parameters
otherThe StackVector to copy from
Returns
Reference to this object

◆ operator=() [2/2]

template<typename T, std::size_t N = 8>
StackVector & nfx::containers::StackVector< T, N >::operator= ( StackVector< T, N > && other)
inlinenoexcept

Move assignment operator.

Parameters
otherThe StackVector to move from
Returns
Reference to this object

◆ operator==()

template<typename T, std::size_t N = 8>
bool nfx::containers::StackVector< T, N >::operator== ( const StackVector< T, N > & other) const
inlinenoexcept

Equality comparison operator.

Parameters
otherThe StackVector to compare with
Returns
true if equal, false otherwise

◆ operator[]() [1/2]

template<typename T, std::size_t N = 8>
const_reference nfx::containers::StackVector< T, N >::operator[] ( size_type pos) const
inlinenoexcept

Access element at position (no bounds checking) const.

Parameters
posPosition of element
Returns
Const reference to element

◆ operator[]() [2/2]

template<typename T, std::size_t N = 8>
reference nfx::containers::StackVector< T, N >::operator[] ( size_type pos)
inlinenoexcept

Access element at position (no bounds checking).

Parameters
posPosition of element
Returns
Reference to element

◆ push_back() [1/2]

template<typename T, std::size_t N = 8>
void nfx::containers::StackVector< T, N >::push_back ( const T & value)
inline

Add element to end (copy).

Parameters
valueThe element to add

◆ push_back() [2/2]

template<typename T, std::size_t N = 8>
void nfx::containers::StackVector< T, N >::push_back ( T && value)
inline

Add element to end (move).

Parameters
valueThe element to add

◆ reserve()

template<typename T, std::size_t N = 8>
void nfx::containers::StackVector< T, N >::reserve ( size_type newCapacity)
inline

Reserve storage for at least specified capacity.

Parameters
newCapacityMinimum capacity to reserve

◆ resize() [1/2]

template<typename T, std::size_t N = 8>
void nfx::containers::StackVector< T, N >::resize ( size_type count)
inline

Resize container to specified size.

Parameters
countNew size

◆ resize() [2/2]

template<typename T, std::size_t N = 8>
void nfx::containers::StackVector< T, N >::resize ( size_type count,
const T & value )
inline

Resize container to specified size with default value.

Parameters
countNew size
valueValue to initialize new elements with

◆ size()

template<typename T, std::size_t N = 8>
StackVector< T, N >::size_type nfx::containers::StackVector< T, N >::size ( ) const
inlinenoexcept

Get number of elements.

Returns
Number of elements in container

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