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

#include <hikogui/container/stack.hpp>

Public Types

using value_type = T
 
using array_type = std::array<value_type, MaxSize>
 
using pointer = array_type::pointer
 
using const_pointer = array_type::const_pointer
 
using reference = array_type::reference
 
using const_reference = array_type::const_reference
 
using iterator = array_type::iterator
 
using const_iterator = array_type::const_iterator
 
using size_type = array_type::size_type
 
using difference_type = array_type::difference_type
 

Public Member Functions

 stack (stack const &)=delete
 
 stack (stack &&)=delete
 
stackoperator= (stack const &)=delete
 
stackoperator= (stack &&)=delete
 
constexpr stack () noexcept
 Construct an empty stack.
 
constexpr const_pointer data () const noexcept
 
constexpr pointer data () noexcept
 
constexpr iterator begin () noexcept
 Get an iterator to the first element on the stack.
 
constexpr const_iterator begin () const noexcept
 Get an iterator to the first element on the stack.
 
constexpr const_iterator cbegin () const noexcept
 Get an iterator to the first element on the stack.
 
constexpr iterator end () noexcept
 Get an iterator to the last element on the stack.
 
constexpr const_iterator end () const noexcept
 Get an iterator to the last element on the stack.
 
constexpr const_iterator 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.
 
constexpr size_type size () const noexcept
 The number of elements that fit on the stack.
 
constexpr bool full () const noexcept
 Check if the stack is full.
 
constexpr bool empty () const noexcept
 Check if the stack is empty.
 
constexpr reference operator[] (std::size_t index) noexcept
 Get a reference to an element on the stack at an index.
 
constexpr const_reference operator[] (std::size_t index) const noexcept
 Get a reference to an element on the stack at an index.
 
constexpr reference at (std::size_t index) noexcept
 Get a reference to an element on the stack at an index.
 
constexpr const_reference at (std::size_t index) const noexcept
 Get a reference to an element on the stack at an index.
 
constexpr reference back () noexcept
 Get a reference to the element at the top of the stack.
 
constexpr const_reference back () const noexcept
 Get a reference to the element at the top of the stack.
 
template<typename... Args>
constexpr 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>)
constexpr void push_back (Arg &&arg) noexcept
 Push a new value to after the current top of the stack.
 
constexpr void pop_back () noexcept
 Remove the value at the top of the stack.
 
constexpr void pop_back (const_iterator new_end) noexcept
 Pop elements of the stack through the given iterator.
 
constexpr void clear () noexcept
 Remove all elements from the stack.
 

Detailed Description

template<typename T, std::size_t MaxSize>
class v1::stack< T, MaxSize >

A static sized stack.

This stack class is meant to be used as a relative small object that lives in an automatic variable. The objects in this stack should be mostly trivial, as they will not be destroyed when the stack is popped or cleared.

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

Constructor & Destructor Documentation

◆ stack()

template<typename T , std::size_t MaxSize>
constexpr v1::stack< T, MaxSize >::stack ( )
inlineconstexprnoexcept

Construct an empty stack.

Member Function Documentation

◆ at() [1/2]

template<typename T , std::size_t MaxSize>
constexpr const_reference v1::stack< T, MaxSize >::at ( std::size_t index) const
inlineconstexprnoexcept

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 , std::size_t MaxSize>
constexpr reference v1::stack< T, MaxSize >::at ( std::size_t index)
inlineconstexprnoexcept

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 , std::size_t MaxSize>
constexpr const_reference v1::stack< T, MaxSize >::back ( ) const
inlineconstexprnoexcept

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 , std::size_t MaxSize>
constexpr reference v1::stack< T, MaxSize >::back ( )
inlineconstexprnoexcept

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 , std::size_t MaxSize>
constexpr const_iterator v1::stack< T, MaxSize >::begin ( ) const
inlineconstexprnoexcept

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 , std::size_t MaxSize>
constexpr iterator v1::stack< T, MaxSize >::begin ( )
inlineconstexprnoexcept

Get an iterator to the first element on the stack.

Returns
An iterator to the first element on the stack.

◆ cbegin()

template<typename T , std::size_t MaxSize>
constexpr const_iterator v1::stack< T, MaxSize >::cbegin ( ) const
inlineconstexprnoexcept

Get an iterator to the first element on the stack.

Returns
An iterator to the first element on the stack.

◆ cend()

template<typename T , std::size_t MaxSize>
constexpr const_iterator v1::stack< T, MaxSize >::cend ( ) const
inlineconstexprnoexcept

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 , std::size_t MaxSize>
constexpr void v1::stack< T, MaxSize >::clear ( )
inlineconstexprnoexcept

Remove all elements from the stack.

◆ emplace_back()

template<typename T , std::size_t MaxSize>
template<typename... Args>
constexpr void v1::stack< T, MaxSize >::emplace_back ( Args &&... args)
inlineconstexprnoexcept

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 , std::size_t MaxSize>
constexpr bool v1::stack< T, MaxSize >::empty ( ) const
inlineconstexprnoexcept

Check if the stack is empty.

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

◆ end() [1/2]

template<typename T , std::size_t MaxSize>
constexpr const_iterator v1::stack< T, MaxSize >::end ( ) const
inlineconstexprnoexcept

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 , std::size_t MaxSize>
constexpr iterator v1::stack< T, MaxSize >::end ( )
inlineconstexprnoexcept

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 , std::size_t MaxSize>
constexpr bool v1::stack< T, MaxSize >::full ( ) const
inlineconstexprnoexcept

Check if the stack is full.

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

◆ max_size()

template<typename T , std::size_t MaxSize>
constexpr size_type v1::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 , std::size_t MaxSize>
constexpr const_reference v1::stack< T, MaxSize >::operator[] ( std::size_t index) const
inlineconstexprnoexcept

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 , std::size_t MaxSize>
constexpr reference v1::stack< T, MaxSize >::operator[] ( std::size_t index)
inlineconstexprnoexcept

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 , std::size_t MaxSize>
constexpr void v1::stack< T, MaxSize >::pop_back ( )
inlineconstexprnoexcept

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 , std::size_t MaxSize>
constexpr void v1::stack< T, MaxSize >::pop_back ( const_iterator new_end)
inlineconstexprnoexcept

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 , std::size_t MaxSize>
template<typename Arg >
requires (std::is_convertible_v<Arg, value_type>)
constexpr void v1::stack< T, MaxSize >::push_back ( Arg && arg)
inlineconstexprnoexcept

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 , std::size_t MaxSize>
constexpr size_type v1::stack< T, MaxSize >::size ( ) const
inlineconstexprnoexcept

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: