COMMS
Template library intended to help with implementation of communication protocols.
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Related Symbols | List of all members
comms::util::StaticVector< T, TSize > Class Template Reference

#include "comms/util/StaticVector.h"

Detailed Description

template<typename T, std::size_t TSize>
class comms::util::StaticVector< T, TSize >

Replacement to std::vector when no dynamic memory allocation is allowed.

Uses std::array in its private members to store the data. Provides almost the same interface as std::vector.

Template Parameters
TType of the stored elements.
TSizeMaximum number of elements that StaticVector can store.

Inherits details::ChooseStaticVectorBase< T, TSize >.

Public Types

using const_iterator = typename Base::const_iterator
 Type of the const iterator.
 
using const_pointer = typename Base::const_pointer
 Const pointer to single element.
 
using const_reference = typename Base::const_reference
 Const reference to single element.
 
using const_reverse_iterator = typename Base::const_reverse_iterator
 Type of the const reverse iterator.
 
using difference_type = typename Base::StorageType::difference_type
 Type used in pointer arithmetics.
 
using iterator = typename Base::iterator
 Type of the iterator.
 
using pointer = typename Base::pointer
 Pointer to single element.
 
using reference = typename Base::reference
 Reference to single element.
 
using reverse_iterator = typename Base::reverse_iterator
 Type of the reverse iterator.
 
using size_type = typename Base::size_type
 Type used for size information.
 
using value_type = typename Base::value_type
 Type of single element.
 

Public Member Functions

 StaticVector ()=default
 Default constructor.
 
 StaticVector (const StaticVector &other)
 Copy constructor.
 
template<std::size_t TOtherSize>
 StaticVector (const StaticVector< T, TOtherSize > &other)
 Copy constructor.
 
 StaticVector (size_type count)
 Constructor.
 
 StaticVector (size_type count, const T &value)
 Constructor.
 
 StaticVector (std::initializer_list< value_type > init)
 Constructor.
 
template<typename TIter >
 StaticVector (TIter from, TIter to)
 Constructor.
 
 ~StaticVector () noexcept=default
 Destructor.
 
void assign (size_type count, const T &value)
 Assigns values to the container.
 
void assign (std::initializer_list< value_type > init)
 Assigns values to the container.
 
template<typename TIter >
void assign (TIter from, TIter to)
 Assigns values to the container.
 
reference at (size_type pos)
 Access specified element with bounds checking.
 
const_reference at (size_type pos) const
 Access specified element with bounds checking.
 
reference back ()
 Access the last element.
 
const_reference back () const
 Access the last element.
 
iterator begin ()
 Returns an iterator to the beginning.
 
const_iterator begin () const
 Returns an iterator to the beginning.
 
size_type capacity () const
 Returns the number of elements that can be held in currently allocated storage.
 
const_iterator cbegin () const
 Returns an iterator to the beginning.
 
const_iterator cend () const
 Returns an iterator to the end.
 
void clear ()
 Clears the contents.
 
const_reverse_iterator crbegin () const
 Returns a reverse iterator to the beginning.
 
const_reverse_iterator crend () const
 Returns a reverse iterator to the end.
 
pointer data ()
 Direct access to the underlying array.
 
const_pointer data () const
 Direct access to the underlying array.
 
template<typename... TArgs>
iterator emplace (const_iterator iter, TArgs &&... args)
 Constructs elements in place.
 
template<typename... TArgs>
void emplace_back (TArgs &&... args)
 Constructs an element in place at the end.
 
bool empty () const
 Checks whether the container is empty.
 
iterator end ()
 Returns an iterator to the end.
 
const_iterator end () const
 Returns an iterator to the end.
 
iterator erase (const_iterator from, const_iterator to)
 Erases elements.
 
iterator erase (const_iterator iter)
 Erases elements.
 
reference front ()
 Access the first element.
 
const_reference front () const
 Access the first element.
 
iterator insert (const_iterator iter, const T &value)
 Inserts elements.
 
iterator insert (const_iterator iter, size_type count, const T &value)
 Inserts elements.
 
iterator insert (const_iterator iter, std::initializer_list< value_type > init)
 Inserts elements.
 
iterator insert (const_iterator iter, T &&value)
 Inserts elements.
 
template<typename TIter >
iterator insert (const_iterator iter, TIter from, TIter to)
 Inserts elements.
 
size_type max_size () const
 Returns the maximum possible number of elements.
 
StaticVectoroperator= (const StaticVector &)=default
 Copy assignement.
 
template<std::size_t TOtherSize>
StaticVectoroperator= (const StaticVector< T, TOtherSize > &other)
 Copy assignement.
 
StaticVectoroperator= (std::initializer_list< value_type > init)
 Copy assignement.
 
reference operator[] (size_type pos)
 Access specified element without bounds checking.
 
const_reference operator[] (size_type pos) const
 Access specified element without bounds checking.
 
void pop_back ()
 Removes the last element.
 
void push_back (const T &value)
 Adds an element to the end.
 
void push_back (T &&value)
 Adds an element to the end.
 
reverse_iterator rbegin ()
 Returns a reverse iterator to the beginning.
 
const_reverse_iterator rbegin () const
 Returns a reverse iterator to the beginning.
 
reverse_iterator rend ()
 Returns a reverse iterator to the end.
 
const_reverse_iterator rend () const
 Returns a reverse iterator to the end.
 
void reserve (size_type new_cap)
 Reserves storage.
 
void resize (size_type count)
 Changes the number of elements stored.
 
void resize (size_type count, const value_type &value)
 Changes the number of elements stored.
 
void shrink_to_fit ()
 Reduces memory usage by freeing unused memory.
 
size_type size () const
 Returns the number of elements.
 
template<std::size_t TOtherSize>
void swap (StaticVector< T, TOtherSize > &other)
 Swaps the contents.
 

Related Symbols

(Note that these are not member symbols.)

template<typename T >
static constexpr bool isStaticVector ()
 Compile time check whether the provided type is a variant of comms::util::StaticVector.
 
template<typename T , std::size_t TSize1, std::size_t TSize2>
bool operator!= (const StaticVector< T, TSize1 > &v1, const StaticVector< T, TSize2 > &v2)
 Lexicographically compares the values in the vector.
 
template<typename T , std::size_t TSize1, std::size_t TSize2>
bool operator< (const StaticVector< T, TSize1 > &v1, const StaticVector< T, TSize2 > &v2)
 Lexicographically compares the values in the vector.
 
template<typename T , std::size_t TSize1, std::size_t TSize2>
bool operator<= (const StaticVector< T, TSize1 > &v1, const StaticVector< T, TSize2 > &v2)
 Lexicographically compares the values in the vector.
 
template<typename T , std::size_t TSize1, std::size_t TSize2>
bool operator== (const StaticVector< T, TSize1 > &v1, const StaticVector< T, TSize2 > &v2)
 Lexicographically compares the values in the vector.
 
template<typename T , std::size_t TSize1, std::size_t TSize2>
bool operator> (const StaticVector< T, TSize1 > &v1, const StaticVector< T, TSize2 > &v2)
 Lexicographically compares the values in the vector.
 
template<typename T , std::size_t TSize1, std::size_t TSize2>
bool operator>= (const StaticVector< T, TSize1 > &v1, const StaticVector< T, TSize2 > &v2)
 Lexicographically compares the values in the vector.
 
template<typename T , std::size_t TSize1, std::size_t TSize2>
void swap (comms::util::StaticVector< T, TSize1 > &v1, comms::util::StaticVector< T, TSize2 > &v2)
 Specializes the std::swap algorithm.
 

Constructor & Destructor Documentation

◆ StaticVector() [1/6]

template<typename T , std::size_t TSize>
comms::util::StaticVector< T, TSize >::StaticVector ( size_type  count,
const T &  value 
)

Constructor.

See also
Reference

◆ StaticVector() [2/6]

template<typename T , std::size_t TSize>
comms::util::StaticVector< T, TSize >::StaticVector ( size_type  count)
explicit

Constructor.

See also
Reference

◆ StaticVector() [3/6]

template<typename T , std::size_t TSize>
template<typename TIter >
comms::util::StaticVector< T, TSize >::StaticVector ( TIter  from,
TIter  to 
)

Constructor.

See also
Reference

◆ StaticVector() [4/6]

template<typename T , std::size_t TSize>
template<std::size_t TOtherSize>
comms::util::StaticVector< T, TSize >::StaticVector ( const StaticVector< T, TOtherSize > &  other)

Copy constructor.

See also
Reference

◆ StaticVector() [5/6]

template<typename T , std::size_t TSize>
comms::util::StaticVector< T, TSize >::StaticVector ( const StaticVector< T, TSize > &  other)

Copy constructor.

See also
Reference

◆ StaticVector() [6/6]

template<typename T , std::size_t TSize>
comms::util::StaticVector< T, TSize >::StaticVector ( std::initializer_list< value_type init)

Constructor.

See also
Reference

Member Function Documentation

◆ assign() [1/3]

template<typename T , std::size_t TSize>
void comms::util::StaticVector< T, TSize >::assign ( size_type  count,
const T &  value 
)

Assigns values to the container.

See also
Reference

◆ assign() [2/3]

template<typename T , std::size_t TSize>
void comms::util::StaticVector< T, TSize >::assign ( std::initializer_list< value_type init)

Assigns values to the container.

See also
Reference

◆ assign() [3/3]

template<typename T , std::size_t TSize>
template<typename TIter >
void comms::util::StaticVector< T, TSize >::assign ( TIter  from,
TIter  to 
)

Assigns values to the container.

See also
Reference

◆ at() [1/2]

template<typename T , std::size_t TSize>
reference comms::util::StaticVector< T, TSize >::at ( size_type  pos)

Access specified element with bounds checking.

The bounds check is performed with COMMS_ASSERT() macro, which means it is performed only in DEBUG mode compilation. In case NDEBUG symbol is defined (RELEASE mode compilation), this call is equivalent to operator[]().

See also
Reference

◆ at() [2/2]

template<typename T , std::size_t TSize>
const_reference comms::util::StaticVector< T, TSize >::at ( size_type  pos) const

Access specified element with bounds checking.

The bounds check is performed with COMMS_ASSERT() macro, which means it is performed only in DEBUG mode compilation. In case NDEBUG symbol is defined (RELEASE mode compilation), this call is equivalent to operator[]().

See also
Reference

◆ back() [1/2]

template<typename T , std::size_t TSize>
reference comms::util::StaticVector< T, TSize >::back ( )

Access the last element.

See also
Reference
Precondition
The vector is not empty.

◆ back() [2/2]

template<typename T , std::size_t TSize>
const_reference comms::util::StaticVector< T, TSize >::back ( ) const

Access the last element.

See also
Reference
Precondition
The vector is not empty.

◆ begin() [1/2]

template<typename T , std::size_t TSize>
iterator comms::util::StaticVector< T, TSize >::begin ( )

Returns an iterator to the beginning.

See also
Reference

◆ begin() [2/2]

template<typename T , std::size_t TSize>
const_iterator comms::util::StaticVector< T, TSize >::begin ( ) const

Returns an iterator to the beginning.

See also
Reference

◆ capacity()

template<typename T , std::size_t TSize>
size_type comms::util::StaticVector< T, TSize >::capacity ( ) const

Returns the number of elements that can be held in currently allocated storage.

Same as max_size().

See also
Reference
Returns
TSize provided as template argument.

◆ cbegin()

template<typename T , std::size_t TSize>
const_iterator comms::util::StaticVector< T, TSize >::cbegin ( ) const

Returns an iterator to the beginning.

See also
Reference

◆ cend()

template<typename T , std::size_t TSize>
const_iterator comms::util::StaticVector< T, TSize >::cend ( ) const

Returns an iterator to the end.

See also
Reference

◆ clear()

template<typename T , std::size_t TSize>
void comms::util::StaticVector< T, TSize >::clear ( )

Clears the contents.

See also
Reference

◆ crbegin()

template<typename T , std::size_t TSize>
const_reverse_iterator comms::util::StaticVector< T, TSize >::crbegin ( ) const

Returns a reverse iterator to the beginning.

See also
Reference

◆ crend()

template<typename T , std::size_t TSize>
const_reverse_iterator comms::util::StaticVector< T, TSize >::crend ( ) const

Returns a reverse iterator to the end.

See also
Reference

◆ data() [1/2]

template<typename T , std::size_t TSize>
pointer comms::util::StaticVector< T, TSize >::data ( )

Direct access to the underlying array.

See also
Reference

◆ data() [2/2]

template<typename T , std::size_t TSize>
const_pointer comms::util::StaticVector< T, TSize >::data ( ) const

Direct access to the underlying array.

See also
Reference

◆ emplace()

template<typename T , std::size_t TSize>
template<typename... TArgs>
iterator comms::util::StaticVector< T, TSize >::emplace ( const_iterator  iter,
TArgs &&...  args 
)

Constructs elements in place.

See also
Reference

◆ emplace_back()

template<typename T , std::size_t TSize>
template<typename... TArgs>
void comms::util::StaticVector< T, TSize >::emplace_back ( TArgs &&...  args)

Constructs an element in place at the end.

See also
Reference
Precondition
The vector mustn't be full.

◆ empty()

template<typename T , std::size_t TSize>
bool comms::util::StaticVector< T, TSize >::empty ( ) const

Checks whether the container is empty.

See also
Reference

◆ end() [1/2]

template<typename T , std::size_t TSize>
iterator comms::util::StaticVector< T, TSize >::end ( )

Returns an iterator to the end.

See also
Reference

◆ end() [2/2]

template<typename T , std::size_t TSize>
const_iterator comms::util::StaticVector< T, TSize >::end ( ) const

Returns an iterator to the end.

See also
Reference

◆ erase() [1/2]

template<typename T , std::size_t TSize>
iterator comms::util::StaticVector< T, TSize >::erase ( const_iterator  from,
const_iterator  to 
)

Erases elements.

See also
Reference

◆ erase() [2/2]

template<typename T , std::size_t TSize>
iterator comms::util::StaticVector< T, TSize >::erase ( const_iterator  iter)

Erases elements.

See also
Reference

◆ front() [1/2]

template<typename T , std::size_t TSize>
reference comms::util::StaticVector< T, TSize >::front ( )

Access the first element.

See also
Reference
Precondition
The vector is not empty.

◆ front() [2/2]

template<typename T , std::size_t TSize>
const_reference comms::util::StaticVector< T, TSize >::front ( ) const

Access the first element.

See also
Reference
Precondition
The vector is not empty.

◆ insert() [1/5]

template<typename T , std::size_t TSize>
iterator comms::util::StaticVector< T, TSize >::insert ( const_iterator  iter,
const T &  value 
)

Inserts elements.

See also
Reference

◆ insert() [2/5]

template<typename T , std::size_t TSize>
iterator comms::util::StaticVector< T, TSize >::insert ( const_iterator  iter,
size_type  count,
const T &  value 
)

Inserts elements.

See also
Reference

◆ insert() [3/5]

template<typename T , std::size_t TSize>
iterator comms::util::StaticVector< T, TSize >::insert ( const_iterator  iter,
std::initializer_list< value_type init 
)

Inserts elements.

See also
Reference

◆ insert() [4/5]

template<typename T , std::size_t TSize>
iterator comms::util::StaticVector< T, TSize >::insert ( const_iterator  iter,
T &&  value 
)

Inserts elements.

See also
Reference

◆ insert() [5/5]

template<typename T , std::size_t TSize>
template<typename TIter >
iterator comms::util::StaticVector< T, TSize >::insert ( const_iterator  iter,
TIter  from,
TIter  to 
)

Inserts elements.

See also
Reference

◆ max_size()

template<typename T , std::size_t TSize>
size_type comms::util::StaticVector< T, TSize >::max_size ( ) const

Returns the maximum possible number of elements.

Same as capacity().

See also
Reference
Returns
TSize provided as template argument.

◆ operator=() [1/3]

template<typename T , std::size_t TSize>
StaticVector & comms::util::StaticVector< T, TSize >::operator= ( const StaticVector< T, TSize > &  )
default

Copy assignement.

See also
Reference

◆ operator=() [2/3]

template<typename T , std::size_t TSize>
template<std::size_t TOtherSize>
StaticVector & comms::util::StaticVector< T, TSize >::operator= ( const StaticVector< T, TOtherSize > &  other)

Copy assignement.

See also
Reference

◆ operator=() [3/3]

template<typename T , std::size_t TSize>
StaticVector & comms::util::StaticVector< T, TSize >::operator= ( std::initializer_list< value_type init)

Copy assignement.

See also
Reference

◆ operator[]() [1/2]

template<typename T , std::size_t TSize>
reference comms::util::StaticVector< T, TSize >::operator[] ( size_type  pos)

Access specified element without bounds checking.

See also
Reference

◆ operator[]() [2/2]

template<typename T , std::size_t TSize>
const_reference comms::util::StaticVector< T, TSize >::operator[] ( size_type  pos) const

Access specified element without bounds checking.

See also
Reference

◆ pop_back()

template<typename T , std::size_t TSize>
void comms::util::StaticVector< T, TSize >::pop_back ( )

Removes the last element.

See also
Reference
Precondition
The vector mustn't be empty.

◆ push_back() [1/2]

template<typename T , std::size_t TSize>
void comms::util::StaticVector< T, TSize >::push_back ( const T &  value)

Adds an element to the end.

See also
Reference
Precondition
The vector mustn't be full.

◆ push_back() [2/2]

template<typename T , std::size_t TSize>
void comms::util::StaticVector< T, TSize >::push_back ( T &&  value)

Adds an element to the end.

See also
Reference
Precondition
The vector mustn't be full.

◆ rbegin() [1/2]

template<typename T , std::size_t TSize>
reverse_iterator comms::util::StaticVector< T, TSize >::rbegin ( )

Returns a reverse iterator to the beginning.

See also
Reference

◆ rbegin() [2/2]

template<typename T , std::size_t TSize>
const_reverse_iterator comms::util::StaticVector< T, TSize >::rbegin ( ) const

Returns a reverse iterator to the beginning.

See also
Reference

◆ rend() [1/2]

template<typename T , std::size_t TSize>
reverse_iterator comms::util::StaticVector< T, TSize >::rend ( )

Returns a reverse iterator to the end.

See also
Reference

◆ rend() [2/2]

template<typename T , std::size_t TSize>
const_reverse_iterator comms::util::StaticVector< T, TSize >::rend ( ) const

Returns a reverse iterator to the end.

See also
Reference

◆ reserve()

template<typename T , std::size_t TSize>
void comms::util::StaticVector< T, TSize >::reserve ( size_type  new_cap)

Reserves storage.

Does nothing.

See also
Reference

◆ resize() [1/2]

template<typename T , std::size_t TSize>
void comms::util::StaticVector< T, TSize >::resize ( size_type  count)

Changes the number of elements stored.

See also
Reference
Precondition
New size mustn't exceed max_size().

◆ resize() [2/2]

template<typename T , std::size_t TSize>
void comms::util::StaticVector< T, TSize >::resize ( size_type  count,
const value_type value 
)

Changes the number of elements stored.

See also
Reference
Precondition
New size mustn't exceed max_size().

◆ shrink_to_fit()

template<typename T , std::size_t TSize>
void comms::util::StaticVector< T, TSize >::shrink_to_fit ( )

Reduces memory usage by freeing unused memory.

Does nothing.

See also
Reference

◆ size()

template<typename T , std::size_t TSize>
size_type comms::util::StaticVector< T, TSize >::size ( ) const

Returns the number of elements.

See also
Reference

◆ swap()

template<typename T , std::size_t TSize>
template<std::size_t TOtherSize>
void comms::util::StaticVector< T, TSize >::swap ( StaticVector< T, TOtherSize > &  other)

Swaps the contents.

See also
Reference
Precondition
New size mustn't exceed max_size().

Friends And Related Symbol Documentation

◆ operator!=()

template<typename T , std::size_t TSize1, std::size_t TSize2>
bool operator!= ( const StaticVector< T, TSize1 > &  v1,
const StaticVector< T, TSize2 > &  v2 
)
related

Lexicographically compares the values in the vector.

See also
Reference

◆ operator<()

template<typename T , std::size_t TSize1, std::size_t TSize2>
bool operator< ( const StaticVector< T, TSize1 > &  v1,
const StaticVector< T, TSize2 > &  v2 
)
related

Lexicographically compares the values in the vector.

See also
Reference

◆ operator<=()

template<typename T , std::size_t TSize1, std::size_t TSize2>
bool operator<= ( const StaticVector< T, TSize1 > &  v1,
const StaticVector< T, TSize2 > &  v2 
)
related

Lexicographically compares the values in the vector.

See also
Reference

◆ operator==()

template<typename T , std::size_t TSize1, std::size_t TSize2>
bool operator== ( const StaticVector< T, TSize1 > &  v1,
const StaticVector< T, TSize2 > &  v2 
)
related

Lexicographically compares the values in the vector.

See also
Reference

◆ operator>()

template<typename T , std::size_t TSize1, std::size_t TSize2>
bool operator> ( const StaticVector< T, TSize1 > &  v1,
const StaticVector< T, TSize2 > &  v2 
)
related

Lexicographically compares the values in the vector.

See also
Reference

◆ operator>=()

template<typename T , std::size_t TSize1, std::size_t TSize2>
bool operator>= ( const StaticVector< T, TSize1 > &  v1,
const StaticVector< T, TSize2 > &  v2 
)
related

Lexicographically compares the values in the vector.

See also
Reference

◆ swap()

template<typename T , std::size_t TSize1, std::size_t TSize2>
void swap ( comms::util::StaticVector< T, TSize1 > &  v1,
comms::util::StaticVector< T, TSize2 > &  v2 
)
related

Specializes the std::swap algorithm.

See also
Reference

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