C++ Channel
Loading...
Searching...
No Matches
Public Member Functions | Static Public Attributes | List of all members
msd::array_storage< T, N > Class Template Reference

A fixed-size circular buffer using std::array. More...

#include <storage.hpp>

Public Member Functions

template<typename Type >
void push_back (Type &&value)
 Adds an element to the back of the array.
 
void pop_front (T &out)
 Marks the front element as removed and moves it to the output.
 
NODISCARD std::size_t size () const noexcept
 Returns the number of elements currently stored.
 

Static Public Attributes

static constexpr std::size_t capacity = N
 The storage capacity.
 

Detailed Description

template<typename T, std::size_t N>
class msd::array_storage< T, N >

A fixed-size circular buffer using std::array.

Template Parameters
TType of elements stored.
NMaximum number of elements (capacity).
Warning
Do not construct manually. The constructor may change anytime.

Member Function Documentation

◆ pop_front()

template<typename T , std::size_t N>
void msd::array_storage< T, N >::pop_front ( T out)
inline

Marks the front element as removed and moves it to the output.

Parameters
outReference to the variable where the front element will be moved.
Warning
It's undefined behaviour to pop from an empty array.

◆ push_back()

template<typename T , std::size_t N>
template<typename Type >
void msd::array_storage< T, N >::push_back ( Type &&  value)
inline

Adds an element to the back of the array.

Template Parameters
TypeType of the element to insert.
Parameters
valueThe value to insert (perfect forwarded).
Warning
It's undefined behaviour to push into a full array.

◆ size()

template<typename T , std::size_t N>
NODISCARD std::size_t msd::array_storage< T, N >::size ( ) const
inlinenoexcept

Returns the number of elements currently stored.

Returns
Current size.

Member Data Documentation

◆ capacity

template<typename T , std::size_t N>
constexpr std::size_t msd::array_storage< T, N >::capacity = N
staticconstexpr

The storage capacity.

Attention
Required for static storage.

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