BCNP 3.2.1
Batched Command Network Protocol
Loading...
Searching...
No Matches
bcnp::StaticVector< T, Capacity > Class Template Reference

Fixed-capacity vector with no heap allocation. More...

#include <static_vector.h>

Public Types

using value_type = T
 Element type.
 
using size_type = std::size_t
 Size/index type.
 
using iterator = T*
 Mutable iterator type.
 
using const_iterator = const T*
 Const iterator type.
 

Public Member Functions

 StaticVector () noexcept=default
 Default constructor - creates empty vector.
 
 StaticVector (std::initializer_list< T > init)
 Construct from initializer list.
 
 StaticVector (const StaticVector &other)
 Copy constructor - deep copies all elements.
 
 StaticVector (StaticVector &&other) noexcept(std::is_nothrow_move_constructible_v< T >)
 Move constructor - moves all elements.
 
StaticVectoroperator= (const StaticVector &other)
 Copy assignment operator.
 
StaticVectoroperator= (StaticVector &&other) noexcept(std::is_nothrow_move_constructible_v< T > &&std::is_nothrow_destructible_v< T >)
 Move assignment operator.
 
 ~StaticVector ()
 Destructor - properly destroys all elements.
 
size_type size () const noexcept
 Get current number of elements.
 
constexpr size_type capacity () const noexcept
 Get maximum capacity (compile-time constant).
 
bool empty () const noexcept
 Check if vector is empty.
 
T & operator[] (size_type index) noexcept
 Access element by index (no bounds checking).
 
const T & operator[] (size_type index) const noexcept
 Access element by index (no bounds checking).
 
T & at (size_type index)
 Access element with bounds checking.
 
const T & at (size_type index) const
 Access element with bounds checking.
 
T & front () noexcept
 Access first element (undefined if empty).
 
const T & front () const noexcept
 Access first element (undefined if empty).
 
T & back () noexcept
 Access last element (undefined if empty).
 
const T & back () const noexcept
 Access last element (undefined if empty).
 
T * data () noexcept
 Get pointer to underlying storage.
 
const T * data () const noexcept
 Get pointer to underlying storage.
 
void clear () noexcept
 Remove all elements.
 
void push_back (const T &value)
 Add element by copy.
 
void push_back (T &&value)
 Add element by move.
 
template<typename... Args>
T & emplace_back (Args &&... args)
 Construct element in-place at end.
 
void pop_back () noexcept
 Remove last element.
 
void resize (size_type new_size)
 Resize the vector.
 
void resize (size_type new_size, const T &value)
 Resize with fill value.
 
void reserve (size_type requested)
 Reserve capacity (no-op for StaticVector).
 
Iterators
iterator begin () noexcept
 
iterator end () noexcept
 
const_iterator begin () const noexcept
 
const_iterator end () const noexcept
 
const_iterator cbegin () const noexcept
 
const_iterator cend () const noexcept
 

Detailed Description

template<typename T, std::size_t Capacity>
class bcnp::StaticVector< T, Capacity >

Fixed-capacity vector with no heap allocation.

Stores elements in-place using aligned storage.

Template Parameters
TElement type
CapacityMaximum number of elements

Definition at line 29 of file static_vector.h.

Member Typedef Documentation

◆ const_iterator

template<typename T , std::size_t Capacity>
using bcnp::StaticVector< T, Capacity >::const_iterator = const T*

Const iterator type.

Definition at line 34 of file static_vector.h.

◆ iterator

template<typename T , std::size_t Capacity>
using bcnp::StaticVector< T, Capacity >::iterator = T*

Mutable iterator type.

Definition at line 33 of file static_vector.h.

◆ size_type

template<typename T , std::size_t Capacity>
using bcnp::StaticVector< T, Capacity >::size_type = std::size_t

Size/index type.

Definition at line 32 of file static_vector.h.

◆ value_type

template<typename T , std::size_t Capacity>
using bcnp::StaticVector< T, Capacity >::value_type = T

Element type.

Definition at line 31 of file static_vector.h.

Constructor & Destructor Documentation

◆ StaticVector() [1/4]

template<typename T , std::size_t Capacity>
bcnp::StaticVector< T, Capacity >::StaticVector ( )
defaultnoexcept

Default constructor - creates empty vector.

◆ StaticVector() [2/4]

template<typename T , std::size_t Capacity>
bcnp::StaticVector< T, Capacity >::StaticVector ( std::initializer_list< T > init)
inline

Construct from initializer list.

Parameters
initElements to copy into the vector
Exceptions
std::out_of_rangeif init.size() > Capacity

Definition at line 44 of file static_vector.h.

Here is the call graph for this function:

◆ StaticVector() [3/4]

template<typename T , std::size_t Capacity>
bcnp::StaticVector< T, Capacity >::StaticVector ( const StaticVector< T, Capacity > & other)
inline

Copy constructor - deep copies all elements.

Parameters
otherVector to copy from

Definition at line 57 of file static_vector.h.

Here is the call graph for this function:

◆ StaticVector() [4/4]

template<typename T , std::size_t Capacity>
bcnp::StaticVector< T, Capacity >::StaticVector ( StaticVector< T, Capacity > && other)
inlinenoexcept

Move constructor - moves all elements.

Parameters
otherVector to move from (left empty after move)

Definition at line 67 of file static_vector.h.

Here is the call graph for this function:

◆ ~StaticVector()

template<typename T , std::size_t Capacity>
bcnp::StaticVector< T, Capacity >::~StaticVector ( )
inline

Destructor - properly destroys all elements.

Definition at line 108 of file static_vector.h.

Here is the call graph for this function:

Member Function Documentation

◆ at() [1/2]

template<typename T , std::size_t Capacity>
T & bcnp::StaticVector< T, Capacity >::at ( size_type index)
inline

Access element with bounds checking.

Parameters
indexElement index
Returns
Reference to element
Exceptions
std::out_of_rangeif index >= size()

Definition at line 145 of file static_vector.h.

Here is the call graph for this function:

◆ at() [2/2]

template<typename T , std::size_t Capacity>
const T & bcnp::StaticVector< T, Capacity >::at ( size_type index) const
inline

Access element with bounds checking.

Parameters
indexElement index
Returns
Reference to element
Exceptions
std::out_of_rangeif index >= size()

Definition at line 153 of file static_vector.h.

Here is the call graph for this function:

◆ back() [1/2]

template<typename T , std::size_t Capacity>
const T & bcnp::StaticVector< T, Capacity >::back ( ) const
inlinenoexcept

Access last element (undefined if empty).

Definition at line 168 of file static_vector.h.

Here is the call graph for this function:

◆ back() [2/2]

template<typename T , std::size_t Capacity>
T & bcnp::StaticVector< T, Capacity >::back ( )
inlinenoexcept

Access last element (undefined if empty).

Definition at line 166 of file static_vector.h.

Here is the call graph for this function:

◆ begin() [1/2]

template<typename T , std::size_t Capacity>
const_iterator bcnp::StaticVector< T, Capacity >::begin ( ) const
inlinenoexcept

Definition at line 123 of file static_vector.h.

Here is the call graph for this function:

◆ begin() [2/2]

template<typename T , std::size_t Capacity>
iterator bcnp::StaticVector< T, Capacity >::begin ( )
inlinenoexcept

Definition at line 121 of file static_vector.h.

Here is the call graph for this function:

◆ capacity()

template<typename T , std::size_t Capacity>
size_type bcnp::StaticVector< T, Capacity >::capacity ( ) const
inlineconstexprnoexcept

Get maximum capacity (compile-time constant).

Definition at line 114 of file static_vector.h.

◆ cbegin()

template<typename T , std::size_t Capacity>
const_iterator bcnp::StaticVector< T, Capacity >::cbegin ( ) const
inlinenoexcept

Definition at line 125 of file static_vector.h.

Here is the call graph for this function:

◆ cend()

template<typename T , std::size_t Capacity>
const_iterator bcnp::StaticVector< T, Capacity >::cend ( ) const
inlinenoexcept

Definition at line 126 of file static_vector.h.

Here is the call graph for this function:

◆ clear()

template<typename T , std::size_t Capacity>
void bcnp::StaticVector< T, Capacity >::clear ( )
inlinenoexcept

Remove all elements.

Destroys elements in reverse order for proper cleanup of interdependent objects.

Definition at line 181 of file static_vector.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ data() [1/2]

template<typename T , std::size_t Capacity>
const T * bcnp::StaticVector< T, Capacity >::data ( ) const
inlinenoexcept

Get pointer to underlying storage.

Definition at line 173 of file static_vector.h.

◆ data() [2/2]

template<typename T , std::size_t Capacity>
T * bcnp::StaticVector< T, Capacity >::data ( )
inlinenoexcept

Get pointer to underlying storage.

Definition at line 171 of file static_vector.h.

Here is the caller graph for this function:

◆ emplace_back()

template<typename T , std::size_t Capacity>
template<typename... Args>
T & bcnp::StaticVector< T, Capacity >::emplace_back ( Args &&... args)
inline

Construct element in-place at end.

Template Parameters
ArgsConstructor argument types
Parameters
argsArguments forwarded to T's constructor
Returns
Reference to newly constructed element
Exceptions
std::out_of_rangeif size() >= Capacity

Definition at line 223 of file static_vector.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ empty()

template<typename T , std::size_t Capacity>
bool bcnp::StaticVector< T, Capacity >::empty ( ) const
inlinenoexcept

Check if vector is empty.

Definition at line 117 of file static_vector.h.

◆ end() [1/2]

template<typename T , std::size_t Capacity>
const_iterator bcnp::StaticVector< T, Capacity >::end ( ) const
inlinenoexcept

Definition at line 124 of file static_vector.h.

Here is the call graph for this function:

◆ end() [2/2]

template<typename T , std::size_t Capacity>
iterator bcnp::StaticVector< T, Capacity >::end ( )
inlinenoexcept

Definition at line 122 of file static_vector.h.

Here is the call graph for this function:

◆ front() [1/2]

template<typename T , std::size_t Capacity>
const T & bcnp::StaticVector< T, Capacity >::front ( ) const
inlinenoexcept

Access first element (undefined if empty).

Definition at line 163 of file static_vector.h.

Here is the call graph for this function:

◆ front() [2/2]

template<typename T , std::size_t Capacity>
T & bcnp::StaticVector< T, Capacity >::front ( )
inlinenoexcept

Access first element (undefined if empty).

Definition at line 161 of file static_vector.h.

Here is the call graph for this function:

◆ operator=() [1/2]

template<typename T , std::size_t Capacity>
StaticVector & bcnp::StaticVector< T, Capacity >::operator= ( const StaticVector< T, Capacity > & other)
inline

Copy assignment operator.

Parameters
otherVector to copy from
Returns
Reference to this

Definition at line 80 of file static_vector.h.

Here is the call graph for this function:

◆ operator=() [2/2]

template<typename T , std::size_t Capacity>
StaticVector & bcnp::StaticVector< T, Capacity >::operator= ( StaticVector< T, Capacity > && other)
inlinenoexcept

Move assignment operator.

Parameters
otherVector to move from (left empty after move)
Returns
Reference to this

Definition at line 95 of file static_vector.h.

Here is the call graph for this function:

◆ operator[]() [1/2]

template<typename T , std::size_t Capacity>
const T & bcnp::StaticVector< T, Capacity >::operator[] ( size_type index) const
inlinenoexcept

Access element by index (no bounds checking).

Parameters
indexElement index
Returns
Reference to element

Definition at line 137 of file static_vector.h.

Here is the call graph for this function:

◆ operator[]() [2/2]

template<typename T , std::size_t Capacity>
T & bcnp::StaticVector< T, Capacity >::operator[] ( size_type index)
inlinenoexcept

Access element by index (no bounds checking).

Parameters
indexElement index
Returns
Reference to element

Definition at line 134 of file static_vector.h.

Here is the call graph for this function:

◆ pop_back()

template<typename T , std::size_t Capacity>
void bcnp::StaticVector< T, Capacity >::pop_back ( )
inlinenoexcept

Remove last element.

Does nothing if vector is empty.

Definition at line 237 of file static_vector.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ push_back() [1/2]

template<typename T , std::size_t Capacity>
void bcnp::StaticVector< T, Capacity >::push_back ( const T & value)
inline

Add element by copy.

Parameters
valueElement to copy
Exceptions
std::out_of_rangeif size() >= Capacity

Definition at line 194 of file static_vector.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ push_back() [2/2]

template<typename T , std::size_t Capacity>
void bcnp::StaticVector< T, Capacity >::push_back ( T && value)
inline

Add element by move.

Parameters
valueElement to move from
Exceptions
std::out_of_rangeif size() >= Capacity

Definition at line 207 of file static_vector.h.

Here is the call graph for this function:

◆ reserve()

template<typename T , std::size_t Capacity>
void bcnp::StaticVector< T, Capacity >::reserve ( size_type requested)
inline

Reserve capacity (no-op for StaticVector).

Provided for API compatibility with std::vector in generic code. Throws if requested capacity exceeds compile-time Capacity.

Parameters
requestedRequested capacity
Exceptions
std::out_of_rangeif requested > Capacity

Definition at line 291 of file static_vector.h.

◆ resize() [1/2]

template<typename T , std::size_t Capacity>
void bcnp::StaticVector< T, Capacity >::resize ( size_type new_size)
inline

Resize the vector.

Shrinking destroys excess elements. Growing default-constructs new ones.

Parameters
new_sizeTarget size
Exceptions
std::out_of_rangeif new_size > Capacity

Definition at line 252 of file static_vector.h.

Here is the call graph for this function:

◆ resize() [2/2]

template<typename T , std::size_t Capacity>
void bcnp::StaticVector< T, Capacity >::resize ( size_type new_size,
const T & value )
inline

Resize with fill value.

Parameters
new_sizeTarget size
valueValue to copy when growing
Exceptions
std::out_of_rangeif new_size > Capacity

Definition at line 270 of file static_vector.h.

Here is the call graph for this function:

◆ size()

template<typename T , std::size_t Capacity>
size_type bcnp::StaticVector< T, Capacity >::size ( ) const
inlinenoexcept

Get current number of elements.

Definition at line 111 of file static_vector.h.


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