Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
PS::StaticVector< T, N > Class Template Reference

A conntainer close to std::vector but the elements are stored in place: There is a fixed capacity and there is no dynamic memory allocation. More...

#include <StaticVector.h>

Public Types

using value_type = T
 
using size_type = decltype(MakeSmallestCapableUnsigned< N >())
 
using difference_type = decltype(MakeSmallestCapableSigned< N >())
 
using reference = value_type &
 
using const_reference = const value_type &
 
using pointer = value_type *
 
using const_pointer = const value_type *
 
using iterator = pointer
 
using const_iterator = const_pointer
 
using reverse_iterator = std::reverse_iterator< iterator >
 
using const_reverse_iterator = std::reverse_iterator< const_iterator >
 

Public Member Functions

 StaticVector ()=default
 
 StaticVector (const StaticVector &other) noexcept(std::is_nothrow_copy_constructible_v< T >)
 
template<size_t OtherN>
 StaticVector (const StaticVector< T, OtherN > &other) noexcept(std::is_nothrow_copy_constructible_v< T >)
 
StaticVectoroperator= (const StaticVector &other) noexcept(std::is_nothrow_copy_constructible_v< T > &&std::is_nothrow_copy_assignable_v< T >)
 
template<size_t OtherN>
StaticVectoroperator= (const StaticVector< T, OtherN > &other) noexcept(std::is_nothrow_copy_constructible_v< T > &&std::is_nothrow_copy_assignable_v< T >)
 
 StaticVector (StaticVector &&other) noexcept(std::is_nothrow_move_constructible_v< T >)
 
template<size_t OtherN>
 StaticVector (StaticVector< T, OtherN > &&other) noexcept(std::is_nothrow_move_constructible_v< T >)
 
StaticVectoroperator= (StaticVector &&other) noexcept(std::is_nothrow_move_constructible_v< T > &&std::is_nothrow_move_assignable_v< T >)
 
template<size_t OtherN>
StaticVectoroperator= (StaticVector< T, OtherN > &&other) noexcept(std::is_nothrow_move_constructible_v< T > &&std::is_nothrow_move_assignable_v< T >)
 
 ~StaticVector ()
 
 StaticVector (const size_type count, const T &value)
 
 StaticVector (const size_type count)
 
 StaticVector (const std::initializer_list< T > init)
 
StaticVectoroperator= (const std::initializer_list< T > init)
 
reference at (const size_type index)
 
const_reference at (const size_type index) const
 
reference operator[] (const size_type index) noexcept
 
const_reference operator[] (const size_type index) const noexcept
 
reference front () noexcept
 
const_reference front () const noexcept
 
reference back () noexcept
 
const_reference back () const noexcept
 
pointer data () noexcept
 
const_pointer data () const noexcept
 
iterator begin () noexcept
 
const_iterator begin () const noexcept
 
const_iterator cbegin () const noexcept
 
iterator end () noexcept
 
const_iterator end () const noexcept
 
const_iterator cend () const noexcept
 
reverse_iterator rbegin () noexcept
 
const_reverse_iterator rbegin () const noexcept
 
const_reverse_iterator crbegin () const noexcept
 
reverse_iterator rend () noexcept
 
const_reverse_iterator rend () const noexcept
 
const_reverse_iterator crend () const noexcept
 
bool empty () const noexcept
 
bool full () const noexcept
 
size_type size () const noexcept
 
constexpr size_type capacity () const noexcept
 
void clear () noexcept
 
iterator insert (const const_iterator location, const T &value)
 Inserts an element at location. More...
 
iterator insert (const const_iterator location, T &&value)
 Same as above but the new element is move-constructed. More...
 
void push_back (const T &value)
 If an exception is thrown this function has no effect (strong exception guarantee). More...
 
void push_back (T &&value)
 If an exception is thrown this function has no effect (strong exception guarantee). More...
 
template<typename... Args>
reference emplace_back (Args &&... args)
 If an exception is thrown this function has no effect (strong exception guarantee). More...
 
void pop_back () noexcept
 
void resize (const size_type newSize)
 Constructs or destructs elements to adjust to newSize. More...
 
void resize (const size_type newSize, const T &value)
 Same as above but uses value to copy-construct the new elements. More...
 

Private Types

using EagerInitialized = std::array< T, N >
 

Private Member Functions

iterator MakeMutableIterator (const const_iterator iter) noexcept
 

Private Attributes

std::array< std::byte, sizeof(T) *N > m_Data
 
size_type m_Size {0}
 

Friends

template<size_t OtherN>
bool operator== (const StaticVector< T, N > &lhs, const StaticVector< T, OtherN > &rhs)
 
template<size_t OtherN>
bool operator!= (const StaticVector< T, N > &lhs, const StaticVector< T, OtherN > &rhs)
 

Detailed Description

template<typename T, size_t N>
class PS::StaticVector< T, N >

A conntainer close to std::vector but the elements are stored in place: There is a fixed capacity and there is no dynamic memory allocation.

Note: moving a StaticVector will be slower than moving a std::vector in case of sizeof(StaticVector) > sizeof(std::vector).

Member Typedef Documentation

◆ const_iterator

template<typename T , size_t N>
using PS::StaticVector< T, N >::const_iterator = const_pointer

◆ const_pointer

template<typename T , size_t N>
using PS::StaticVector< T, N >::const_pointer = const value_type*

◆ const_reference

template<typename T , size_t N>
using PS::StaticVector< T, N >::const_reference = const value_type&

◆ const_reverse_iterator

template<typename T , size_t N>
using PS::StaticVector< T, N >::const_reverse_iterator = std::reverse_iterator<const_iterator>

◆ difference_type

template<typename T , size_t N>
using PS::StaticVector< T, N >::difference_type = decltype(MakeSmallestCapableSigned<N>())

◆ EagerInitialized

template<typename T , size_t N>
using PS::StaticVector< T, N >::EagerInitialized = std::array<T, N>
private

◆ iterator

template<typename T , size_t N>
using PS::StaticVector< T, N >::iterator = pointer

◆ pointer

template<typename T , size_t N>
using PS::StaticVector< T, N >::pointer = value_type*

◆ reference

template<typename T , size_t N>
using PS::StaticVector< T, N >::reference = value_type&

◆ reverse_iterator

template<typename T , size_t N>
using PS::StaticVector< T, N >::reverse_iterator = std::reverse_iterator<iterator>

◆ size_type

template<typename T , size_t N>
using PS::StaticVector< T, N >::size_type = decltype(MakeSmallestCapableUnsigned<N>())

◆ value_type

template<typename T , size_t N>
using PS::StaticVector< T, N >::value_type = T

Constructor & Destructor Documentation

◆ StaticVector() [1/8]

template<typename T , size_t N>
PS::StaticVector< T, N >::StaticVector ( )
default

◆ StaticVector() [2/8]

template<typename T , size_t N>
PS::StaticVector< T, N >::StaticVector ( const StaticVector< T, N > &  other)
inlinenoexcept

◆ StaticVector() [3/8]

template<typename T , size_t N>
template<size_t OtherN>
PS::StaticVector< T, N >::StaticVector ( const StaticVector< T, OtherN > &  other)
inlineexplicitnoexcept

◆ StaticVector() [4/8]

template<typename T , size_t N>
PS::StaticVector< T, N >::StaticVector ( StaticVector< T, N > &&  other)
inlinenoexcept

◆ StaticVector() [5/8]

template<typename T , size_t N>
template<size_t OtherN>
PS::StaticVector< T, N >::StaticVector ( StaticVector< T, OtherN > &&  other)
inlineexplicitnoexcept

◆ ~StaticVector()

template<typename T , size_t N>
PS::StaticVector< T, N >::~StaticVector ( )
inline

◆ StaticVector() [6/8]

template<typename T , size_t N>
PS::StaticVector< T, N >::StaticVector ( const size_type  count,
const T value 
)
inline

◆ StaticVector() [7/8]

template<typename T , size_t N>
PS::StaticVector< T, N >::StaticVector ( const size_type  count)
inline

◆ StaticVector() [8/8]

template<typename T , size_t N>
PS::StaticVector< T, N >::StaticVector ( const std::initializer_list< T init)
inline

Member Function Documentation

◆ at() [1/2]

template<typename T , size_t N>
reference PS::StaticVector< T, N >::at ( const size_type  index)
inline

◆ at() [2/2]

template<typename T , size_t N>
const_reference PS::StaticVector< T, N >::at ( const size_type  index) const
inline

◆ back() [1/2]

template<typename T , size_t N>
const_reference PS::StaticVector< T, N >::back ( ) const
inlinenoexcept

◆ back() [2/2]

template<typename T , size_t N>
reference PS::StaticVector< T, N >::back ( )
inlinenoexcept

◆ begin() [1/2]

template<typename T , size_t N>
const_iterator PS::StaticVector< T, N >::begin ( ) const
inlinenoexcept

◆ begin() [2/2]

template<typename T , size_t N>
iterator PS::StaticVector< T, N >::begin ( )
inlinenoexcept

◆ capacity()

template<typename T , size_t N>
constexpr size_type PS::StaticVector< T, N >::capacity ( ) const
inlineconstexprnoexcept

◆ cbegin()

template<typename T , size_t N>
const_iterator PS::StaticVector< T, N >::cbegin ( ) const
inlinenoexcept

◆ cend()

template<typename T , size_t N>
const_iterator PS::StaticVector< T, N >::cend ( ) const
inlinenoexcept

◆ clear()

template<typename T , size_t N>
void PS::StaticVector< T, N >::clear ( )
inlinenoexcept

◆ crbegin()

template<typename T , size_t N>
const_reverse_iterator PS::StaticVector< T, N >::crbegin ( ) const
inlinenoexcept

◆ crend()

template<typename T , size_t N>
const_reverse_iterator PS::StaticVector< T, N >::crend ( ) const
inlinenoexcept

◆ data() [1/2]

template<typename T , size_t N>
const_pointer PS::StaticVector< T, N >::data ( ) const
inlinenoexcept

◆ data() [2/2]

template<typename T , size_t N>
pointer PS::StaticVector< T, N >::data ( )
inlinenoexcept

◆ emplace_back()

template<typename T , size_t N>
template<typename... Args>
reference PS::StaticVector< T, N >::emplace_back ( Args &&...  args)
inline

If an exception is thrown this function has no effect (strong exception guarantee).

◆ empty()

template<typename T , size_t N>
bool PS::StaticVector< T, N >::empty ( ) const
inlinenoexcept

◆ end() [1/2]

template<typename T , size_t N>
const_iterator PS::StaticVector< T, N >::end ( ) const
inlinenoexcept

◆ end() [2/2]

template<typename T , size_t N>
iterator PS::StaticVector< T, N >::end ( )
inlinenoexcept

◆ front() [1/2]

template<typename T , size_t N>
const_reference PS::StaticVector< T, N >::front ( ) const
inlinenoexcept

◆ front() [2/2]

template<typename T , size_t N>
reference PS::StaticVector< T, N >::front ( )
inlinenoexcept

◆ full()

template<typename T , size_t N>
bool PS::StaticVector< T, N >::full ( ) const
inlinenoexcept

◆ insert() [1/2]

template<typename T , size_t N>
iterator PS::StaticVector< T, N >::insert ( const const_iterator  location,
const T value 
)
inline

Inserts an element at location.

The elements which were in the range [ location, end() ) get moved no the next position.

Exceptions: If an exception is thrown when inserting an element at the end this function has no effect (strong exception guarantee). Otherwise the program is in a valid state (Basic exception guarantee).

◆ insert() [2/2]

template<typename T , size_t N>
iterator PS::StaticVector< T, N >::insert ( const const_iterator  location,
T &&  value 
)
inline

Same as above but the new element is move-constructed.

If an exception is thrown when inserting an element at the end this function has no effect (strong exception guarantee). If an exception is thrown the program is in a valid state (Basic exception guarantee).

◆ MakeMutableIterator()

template<typename T , size_t N>
iterator PS::StaticVector< T, N >::MakeMutableIterator ( const const_iterator  iter)
inlineprivatenoexcept

◆ operator=() [1/5]

template<typename T , size_t N>
StaticVector & PS::StaticVector< T, N >::operator= ( const StaticVector< T, N > &  other)
inlinenoexcept

◆ operator=() [2/5]

template<typename T , size_t N>
template<size_t OtherN>
StaticVector & PS::StaticVector< T, N >::operator= ( const StaticVector< T, OtherN > &  other)
inlinenoexcept

◆ operator=() [3/5]

template<typename T , size_t N>
StaticVector & PS::StaticVector< T, N >::operator= ( const std::initializer_list< T init)
inline

◆ operator=() [4/5]

template<typename T , size_t N>
StaticVector & PS::StaticVector< T, N >::operator= ( StaticVector< T, N > &&  other)
inlinenoexcept

◆ operator=() [5/5]

template<typename T , size_t N>
template<size_t OtherN>
StaticVector & PS::StaticVector< T, N >::operator= ( StaticVector< T, OtherN > &&  other)
inlinenoexcept

◆ operator[]() [1/2]

template<typename T , size_t N>
const_reference PS::StaticVector< T, N >::operator[] ( const size_type  index) const
inlinenoexcept

◆ operator[]() [2/2]

template<typename T , size_t N>
reference PS::StaticVector< T, N >::operator[] ( const size_type  index)
inlinenoexcept

◆ pop_back()

template<typename T , size_t N>
void PS::StaticVector< T, N >::pop_back ( )
inlinenoexcept

◆ push_back() [1/2]

template<typename T , size_t N>
void PS::StaticVector< T, N >::push_back ( const T value)
inline

If an exception is thrown this function has no effect (strong exception guarantee).

◆ push_back() [2/2]

template<typename T , size_t N>
void PS::StaticVector< T, N >::push_back ( T &&  value)
inline

If an exception is thrown this function has no effect (strong exception guarantee).

◆ rbegin() [1/2]

template<typename T , size_t N>
const_reverse_iterator PS::StaticVector< T, N >::rbegin ( ) const
inlinenoexcept

◆ rbegin() [2/2]

template<typename T , size_t N>
reverse_iterator PS::StaticVector< T, N >::rbegin ( )
inlinenoexcept

◆ rend() [1/2]

template<typename T , size_t N>
const_reverse_iterator PS::StaticVector< T, N >::rend ( ) const
inlinenoexcept

◆ rend() [2/2]

template<typename T , size_t N>
reverse_iterator PS::StaticVector< T, N >::rend ( )
inlinenoexcept

◆ resize() [1/2]

template<typename T , size_t N>
void PS::StaticVector< T, N >::resize ( const size_type  newSize)
inline

Constructs or destructs elements to adjust to newSize.

After this call the StaticVector contains newSize elements. Unlike std::vector the capacity does not get changed. If newSize is bigger then the capacity a CapacityExceededException is thrown.

If newSize is smaller than size() (shrinking) no exception is thrown (Nothrow exception guarantee). If an exception is thrown this function has no effect. (strong exception guarantee)

◆ resize() [2/2]

template<typename T , size_t N>
void PS::StaticVector< T, N >::resize ( const size_type  newSize,
const T value 
)
inline

Same as above but uses value to copy-construct the new elements.

If newSize is smaller than size() (shrinking) no exception is thrown (Nothrow exception guarantee). If an exception is thrown this function has no effect. (strong exception guarantee)

◆ size()

template<typename T , size_t N>
size_type PS::StaticVector< T, N >::size ( ) const
inlinenoexcept

Friends And Related Function Documentation

◆ operator!=

template<typename T , size_t N>
template<size_t OtherN>
bool operator!= ( const StaticVector< T, N > &  lhs,
const StaticVector< T, OtherN > &  rhs 
)
friend

◆ operator==

template<typename T , size_t N>
template<size_t OtherN>
bool operator== ( const StaticVector< T, N > &  lhs,
const StaticVector< T, OtherN > &  rhs 
)
friend

Member Data Documentation

◆ m_Data

template<typename T , size_t N>
std::array<std::byte, sizeof(T) * N> PS::StaticVector< T, N >::m_Data
private

◆ m_Size

template<typename T , size_t N>
size_type PS::StaticVector< T, N >::m_Size {0}
private

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