HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
Public Types | Public Member Functions
tt::stack< T, MaxSize > Class Template Reference

#include <ttauri/stack.hpp>

Public Types

using value_type = T
 
using pointer_type = value_type *
 
using const_pointer_type = value_type const *
 
using reference_type = value_type &
 
using const_reference_type = value_type const &
 
using iterator_type = pointer_type
 
using const_iterator_type = const_pointer_type
 
using size_type = size_t
 
using difference_type = ptrdiff_t
 

Public Member Functions

 stack () noexcept
 Construct an empty stack.
 
 stack (std::initializer_list< value_type > init) noexcept
 Construct a stack with the given data.
 
iterator_type begin () noexcept
 Get an iterator to the first element on the stack.
 
const_iterator_type begin () const noexcept
 Get an iterator to the first element on the stack.
 
const_iterator_type cbegin () const noexcept
 Get an iterator to the first element on the stack.
 
iterator_type end () noexcept
 Get an iterator to the last element on the stack.
 
const_iterator_type end () const noexcept
 Get an iterator to the last element on the stack.
 
const_iterator_type cend () const noexcept
 Get an iterator to the last element on the stack.
 
constexpr size_type max_size () const noexcept
 The maximum number of elements that fit on the stack.
 
size_type size () const noexcept
 The number of elements that fit on the stack.
 
bool full () const noexcept
 Check if the stack is full.
 
bool empty () const noexcept
 Check if the stack is empty.
 
reference_type operator[] (size_t index) noexcept
 Get a reference to an element on the stack at an index.
 
const_reference_type operator[] (size_t index) const noexcept
 Get a reference to an element on the stack at an index.
 
reference_type at (size_t index) noexcept
 Get a reference to an element on the stack at an index.
 
const_reference_type at (size_t index) const noexcept
 Get a reference to an element on the stack at an index.
 
reference_type back () noexcept
 Get a reference to the element at the top of the stack.
 
const_reference_type back () const noexcept
 Get a reference to the element at the top of the stack.
 
template<typename... Args>
void emplace_back (Args &&... args) noexcept
 Construct an object after the current top of the stack.
 
template<typename Arg >
requires (std::is_convertible_v<Arg,value_type>)
void push_back (Arg &&arg) noexcept
 Push a new value to after the current top of the stack.
 
void pop_back () noexcept
 Remove the value at the top of the stack.
 
void pop_back (iterator_type new_end) noexcept
 Pop elements of the stack through the given iterator.
 
void clear () noexcept
 Remove all elements from the stack.
 

Detailed Description

template<typename T, size_t MaxSize>
class tt::stack< T, MaxSize >

A static sized stack.

This stack is designed around the functionality of a std::vector, except the data is allocated locally inside the object instead of on the heap.

Because the stack can not grow or shrink, the iterators remain valid over the lifetime of the stack.

Constructor & Destructor Documentation

◆ stack() [1/2]

template<typename T , size_t MaxSize>
tt::stack< T, MaxSize >::stack ( )
inlinenoexcept

Construct an empty stack.

◆ stack() [2/2]

template<typename T , size_t MaxSize>
tt::stack< T, MaxSize >::stack ( std::initializer_list< value_type > init)
inlinenoexcept

Construct a stack with the given data.

Parameters
initAn initializer_list of items to add to the stack.

Member Function Documentation

◆ at() [1/2]

template<typename T , size_t MaxSize>
const_reference_type tt::stack< T, MaxSize >::at ( size_t index) const
inlinenoexcept

Get a reference to an element on the stack at an index.

Exceptions
std::out_of_rangewhen the index points beyond the top of the stack.
Returns
True if the stack is empty, empty if otherwise.

◆ at() [2/2]

template<typename T , size_t MaxSize>
reference_type tt::stack< T, MaxSize >::at ( size_t index)
inlinenoexcept

Get a reference to an element on the stack at an index.

Exceptions
std::out_of_rangewhen the index points beyond the top of the stack.
Returns
True if the stack is empty, empty if otherwise.

◆ back() [1/2]

template<typename T , size_t MaxSize>
const_reference_type tt::stack< T, MaxSize >::back ( ) const
inlinenoexcept

Get a reference to the element at the top of the stack.

Calling back() on an empty container causes undefined behavior.

◆ back() [2/2]

template<typename T , size_t MaxSize>
reference_type tt::stack< T, MaxSize >::back ( )
inlinenoexcept

Get a reference to the element at the top of the stack.

Calling back() on an empty container causes undefined behavior.

◆ begin() [1/2]

template<typename T , size_t MaxSize>
const_iterator_type tt::stack< T, MaxSize >::begin ( ) const
inlinenoexcept

Get an iterator to the first element on the stack.

Returns
An iterator to the first element on the stack.

◆ begin() [2/2]

template<typename T , size_t MaxSize>
iterator_type tt::stack< T, MaxSize >::begin ( )
inlinenoexcept

Get an iterator to the first element on the stack.

Returns
An iterator to the first element on the stack.

◆ cbegin()

template<typename T , size_t MaxSize>
const_iterator_type tt::stack< T, MaxSize >::cbegin ( ) const
inlinenoexcept

Get an iterator to the first element on the stack.

Returns
An iterator to the first element on the stack.

◆ cend()

template<typename T , size_t MaxSize>
const_iterator_type tt::stack< T, MaxSize >::cend ( ) const
inlinenoexcept

Get an iterator to the last element on the stack.

Returns
An iterator one beyond the last element on the stack.

◆ clear()

template<typename T , size_t MaxSize>
void tt::stack< T, MaxSize >::clear ( )
inlinenoexcept

Remove all elements from the stack.

◆ emplace_back()

template<typename T , size_t MaxSize>
template<typename... Args>
void tt::stack< T, MaxSize >::emplace_back ( Args &&... args)
inlinenoexcept

Construct an object after the current top of the stack.

Template Parameters
ArgsThe types of each argument
Parameters
argsThe arguments for the constructor of value_type.

◆ empty()

template<typename T , size_t MaxSize>
bool tt::stack< T, MaxSize >::empty ( ) const
inlinenoexcept

Check if the stack is empty.

Returns
True if the stack is empty, empty if otherwise.

◆ end() [1/2]

template<typename T , size_t MaxSize>
const_iterator_type tt::stack< T, MaxSize >::end ( ) const
inlinenoexcept

Get an iterator to the last element on the stack.

Returns
An iterator one beyond the last element on the stack.

◆ end() [2/2]

template<typename T , size_t MaxSize>
iterator_type tt::stack< T, MaxSize >::end ( )
inlinenoexcept

Get an iterator to the last element on the stack.

Returns
An iterator one beyond the last element on the stack.

◆ full()

template<typename T , size_t MaxSize>
bool tt::stack< T, MaxSize >::full ( ) const
inlinenoexcept

Check if the stack is full.

Returns
True if the stack is full, empty if otherwise.

◆ max_size()

template<typename T , size_t MaxSize>
constexpr size_type tt::stack< T, MaxSize >::max_size ( ) const
inlineconstexprnoexcept

The maximum number of elements that fit on the stack.

Returns
the maximum number of elements that fit on the stack.

◆ operator[]() [1/2]

template<typename T , size_t MaxSize>
const_reference_type tt::stack< T, MaxSize >::operator[] ( size_t index) const
inlinenoexcept

Get a reference to an element on the stack at an index.

No bounds checking is performed.

Returns
True if the stack is empty, empty if otherwise.

◆ operator[]() [2/2]

template<typename T , size_t MaxSize>
reference_type tt::stack< T, MaxSize >::operator[] ( size_t index)
inlinenoexcept

Get a reference to an element on the stack at an index.

No bounds checking is performed.

Returns
True if the stack is empty, empty if otherwise.

◆ pop_back() [1/2]

template<typename T , size_t MaxSize>
void tt::stack< T, MaxSize >::pop_back ( )
inlinenoexcept

Remove the value at the top of the stack.

It is undefined behaviour to call this function on an empty stack.

◆ pop_back() [2/2]

template<typename T , size_t MaxSize>
void tt::stack< T, MaxSize >::pop_back ( iterator_type new_end)
inlinenoexcept

Pop elements of the stack through the given iterator.

Pop elements up to and including the element at new_end.

Parameters
new_endIterator to the object to be removed.

◆ push_back()

template<typename T , size_t MaxSize>
template<typename Arg >
requires (std::is_convertible_v<Arg,value_type>)
void tt::stack< T, MaxSize >::push_back ( Arg && arg)
inlinenoexcept

Push a new value to after the current top of the stack.

Template Parameters
ArgThe type of an object that can be converted to value_type
Parameters
argThe object to be pushed on the stack.

◆ size()

template<typename T , size_t MaxSize>
size_type tt::stack< T, MaxSize >::size ( ) const
inlinenoexcept

The number of elements that fit on the stack.

Returns
the number of elements that fit on the stack.

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