Thea
Public Types | Public Member Functions | Static Public Member Functions | List of all members
BoundedArrayN< N, T > Class Template Reference

An array of bounded maximum size N, stored on the stack. More...

#include <BoundedArrayN.hpp>

Public Types

typedef T const * const_iterator
 Iterator over immutable elements. More...
 
typedef std::reverse_iterator< const_iteratorconst_reverse_iterator
 Reverse iterator over immutable elements. More...
 
typedef T * iterator
 Iterator over elements. More...
 
typedef std::reverse_iterator< iteratorreverse_iterator
 Reverse iterator over elements. More...
 

Public Member Functions

void append (T const &t)
 Add a new element to the end of array, if it is not full. More...
 
iterator begin () noexcept
 Iterator to the beginning of the array. More...
 
const_iterator begin () const noexcept
 Iterator to the beginning of the array. More...
 
 BoundedArrayN ()
 Constructor. More...
 
const_iterator cbegin () const noexcept
 Iterator to the beginning of the array. More...
 
const_iterator cend () const noexcept
 Iterator to the end of the array. More...
 
void clear ()
 Remove all elements from the array. More...
 
const_reverse_iterator crbegin () const noexcept
 Reverse iterator to the beginning of the array. More...
 
T const * data () const
 Get a pointer to the data buffer. More...
 
T * data ()
 Get a pointer to the data buffer. More...
 
bool empty () const
 Check if the array is empty or not. More...
 
iterator end () noexcept
 Iterator to the end of the array. More...
 
const_iterator end () const noexcept
 Iterator to the end of the array. More...
 
void erase (size_t i)
 Remove the element at the given position from the array. More...
 
T const & first () const
 Get the first element in the array. More...
 
void insert (size_t i, T const &t)
 Insert an element at a given position in the array, shifting all existing elements at or after this position up by one position to make space. More...
 
bool isFull () const
 Check if the array has reached maximum capacity or not. More...
 
T const & last () const
 Get the last element in the array. More...
 
T const & operator[] (size_t i) const
 Get the element at a given position in the array. More...
 
T & operator[] (size_t i)
 Get the element at a given position in the array. More...
 
void push_back (T const &t)
 Add a new element to the end of array, if it is not full (STL-style syntax). More...
 
reverse_iterator rbegin () noexcept
 Reverse iterator to the end of the array. More...
 
const_reverse_iterator rbegin () const noexcept
 Reverse iterator to the end of the array. More...
 
reverse_iterator rend () noexcept
 Reverse iterator to the beginning of the array. More...
 
const_reverse_iterator rend () const noexcept
 Reverse iterator to the beginning of the array. More...
 
size_t size () const
 Get the number of elements in the array. More...
 

Static Public Member Functions

static constexpr size_t getCapacity ()
 Get the maximum number of elements the array can hold. More...
 

Detailed Description

template<size_t N, typename T>
class Thea::BoundedArrayN< N, T >

An array of bounded maximum size N, stored on the stack.

No new elements can be added to the end of the array once it reaches its maximum capacity, until some are removed via erase(). Elements can be inserted in the middle of the array even when it is full: in this case the last element is dropped to make space. This class is useful for very fast allocation of space for a few elements, where the exact number of elements is not known but is guaranteed to have an upper limit.

To get some extra speed when T has a trivial (bit-copy) assignment operator, make sure that std::is_trivially_copyable is true for T.

The implementation always allocates enough space to store the maximum number of instances of T. The capacity N should be positive (non-zero).

For a bounded stack-based array that also guarantees that its elements are in sorted order, see BoundedSortedArrayN.

Definition at line 39 of file BoundedArrayN.hpp.

Member Typedef Documentation

typedef T const* const_iterator

Iterator over immutable elements.

Definition at line 49 of file BoundedArrayN.hpp.

typedef std::reverse_iterator<const_iterator> const_reverse_iterator

Reverse iterator over immutable elements.

Definition at line 51 of file BoundedArrayN.hpp.

typedef T* iterator

Iterator over elements.

Definition at line 48 of file BoundedArrayN.hpp.

typedef std::reverse_iterator<iterator> reverse_iterator

Reverse iterator over elements.

Definition at line 50 of file BoundedArrayN.hpp.

Constructor & Destructor Documentation

Constructor.

Definition at line 54 of file BoundedArrayN.hpp.

Member Function Documentation

void append ( T const &  t)

Add a new element to the end of array, if it is not full.

If the array is full, the operation fails silently.

Definition at line 126 of file BoundedArrayN.hpp.

iterator begin ( )
noexcept

Iterator to the beginning of the array.

Definition at line 74 of file BoundedArrayN.hpp.

const_iterator begin ( ) const
noexcept

Iterator to the beginning of the array.

Definition at line 75 of file BoundedArrayN.hpp.

const_iterator cbegin ( ) const
noexcept

Iterator to the beginning of the array.

Definition at line 76 of file BoundedArrayN.hpp.

const_iterator cend ( ) const
noexcept

Iterator to the end of the array.

Reverse iterator to the end of the array.

Definition at line 79 of file BoundedArrayN.hpp.

void clear ( )

Remove all elements from the array.

Definition at line 170 of file BoundedArrayN.hpp.

const_reverse_iterator crbegin ( ) const
noexcept

Reverse iterator to the beginning of the array.

Definition at line 86 of file BoundedArrayN.hpp.

T const* data ( ) const

Get a pointer to the data buffer.

Definition at line 69 of file BoundedArrayN.hpp.

T* data ( )

Get a pointer to the data buffer.

Definition at line 72 of file BoundedArrayN.hpp.

bool empty ( ) const

Check if the array is empty or not.

Definition at line 63 of file BoundedArrayN.hpp.

iterator end ( )
noexcept

Iterator to the end of the array.

Definition at line 77 of file BoundedArrayN.hpp.

const_iterator end ( ) const
noexcept

Iterator to the end of the array.

Definition at line 78 of file BoundedArrayN.hpp.

void erase ( size_t  i)

Remove the element at the given position from the array.

Definition at line 160 of file BoundedArrayN.hpp.

T const& first ( ) const

Get the first element in the array.

Definition at line 98 of file BoundedArrayN.hpp.

static constexpr size_t getCapacity ( )
static

Get the maximum number of elements the array can hold.

Definition at line 57 of file BoundedArrayN.hpp.

void insert ( size_t  i,
T const &  t 
)

Insert an element at a given position in the array, shifting all existing elements at or after this position up by one position to make space.

If the array is full, the last element is dropped.

Definition at line 146 of file BoundedArrayN.hpp.

bool isFull ( ) const

Check if the array has reached maximum capacity or not.

Definition at line 66 of file BoundedArrayN.hpp.

T const& last ( ) const

Get the last element in the array.

Definition at line 105 of file BoundedArrayN.hpp.

T const& operator[] ( size_t  i) const

Get the element at a given position in the array.

Bounds checks are only performed in debug mode.

Definition at line 112 of file BoundedArrayN.hpp.

T& operator[] ( size_t  i)

Get the element at a given position in the array.

Bounds checks are only performed in debug mode.

Definition at line 119 of file BoundedArrayN.hpp.

void push_back ( T const &  t)

Add a new element to the end of array, if it is not full (STL-style syntax).

If the array is full, the operation fails silently.

Definition at line 140 of file BoundedArrayN.hpp.

reverse_iterator rbegin ( )
noexcept

Reverse iterator to the end of the array.

Definition at line 80 of file BoundedArrayN.hpp.

const_reverse_iterator rbegin ( ) const
noexcept

Reverse iterator to the end of the array.

Definition at line 83 of file BoundedArrayN.hpp.

reverse_iterator rend ( )
noexcept

Reverse iterator to the beginning of the array.

Definition at line 89 of file BoundedArrayN.hpp.

const_reverse_iterator rend ( ) const
noexcept

Reverse iterator to the beginning of the array.

Definition at line 92 of file BoundedArrayN.hpp.

size_t size ( ) const

Get the number of elements in the array.

Definition at line 60 of file BoundedArrayN.hpp.


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