7#include "../utility/utility.hpp"
8#include "../macros.hpp"
11#include <initializer_list>
15hi_export_module(hikogui.container.stack);
17hi_export
namespace hi::inline
v1 {
29template<
typename T, std::
size_t MaxSize>
34 using pointer = array_type::pointer;
35 using const_pointer = array_type::const_pointer;
36 using reference = array_type::reference;
37 using const_reference = array_type::const_reference;
38 using iterator = array_type::iterator;
39 using const_iterator = array_type::const_iterator;
40 using size_type = array_type::size_type;
41 using difference_type = array_type::difference_type;
43 constexpr ~stack()
noexcept =
default;
56 [[nodiscard]]
constexpr const_pointer data() const noexcept
61 [[nodiscard]]
constexpr pointer data() noexcept
69 [[nodiscard]]
constexpr iterator
begin() noexcept
77 [[nodiscard]]
constexpr const_iterator
begin() const noexcept
85 [[nodiscard]]
constexpr const_iterator
cbegin() const noexcept
87 return _data.cbegin();
93 [[nodiscard]]
constexpr iterator
end() noexcept
101 [[nodiscard]]
constexpr const_iterator
end() const noexcept
109 [[nodiscard]]
constexpr const_iterator
cend() const noexcept
117 [[nodiscard]]
constexpr size_type
max_size() const noexcept
125 [[nodiscard]]
constexpr size_type
size() const noexcept
127 return narrow_cast<size_type>(
std::distance(begin(), end()));
133 [[nodiscard]]
constexpr bool full() const noexcept
135 return _top == _data.end();
141 [[nodiscard]]
constexpr bool empty() const noexcept
143 return _top == _data.begin();
152 hi_axiom_bounds(index, *
this);
162 hi_axiom_bounds(index, *
this);
172 if (index >= size()) {
182 [[nodiscard]]
constexpr const_reference
at(
std::size_t index)
const noexcept
184 if (index >= size()) {
193 [[nodiscard]]
constexpr reference
back() noexcept
195 hi_axiom(not empty());
202 [[nodiscard]]
constexpr const_reference
back() const noexcept
204 hi_axiom(not empty());
212 template<
typename... Args>
215 hi_axiom(not full());
216 *(_top++) = value_type(std::forward<Args>(args)...);
223 template<
typename Arg>
225 requires(std::is_convertible_v<Arg, value_type>)
227 hi_axiom(not full());
228 *(_top++) = std::forward<Arg>(arg);
236 hi_axiom(not empty());
244 constexpr void pop_back(const_iterator new_end)
noexcept
246 while (_top != new_end) {
255 _top = _data.begin();
260 array_type::iterator _top;
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
A static sized stack.
Definition stack.hpp:30
constexpr const_iterator end() const noexcept
Get an iterator to the last element on the stack.
Definition stack.hpp:101
constexpr bool full() const noexcept
Check if the stack is full.
Definition stack.hpp:133
constexpr const_iterator cend() const noexcept
Get an iterator to the last element on the stack.
Definition stack.hpp:109
constexpr const_iterator begin() const noexcept
Get an iterator to the first element on the stack.
Definition stack.hpp:77
constexpr iterator end() noexcept
Get an iterator to the last element on the stack.
Definition stack.hpp:93
constexpr stack() noexcept
Construct an empty stack.
Definition stack.hpp:51
constexpr bool empty() const noexcept
Check if the stack is empty.
Definition stack.hpp:141
constexpr void emplace_back(Args &&...args) noexcept
Construct an object after the current top of the stack.
Definition stack.hpp:213
constexpr size_type size() const noexcept
The number of elements that fit on the stack.
Definition stack.hpp:125
constexpr void pop_back(const_iterator new_end) noexcept
Pop elements of the stack through the given iterator.
Definition stack.hpp:244
constexpr reference at(std::size_t index) noexcept
Get a reference to an element on the stack at an index.
Definition stack.hpp:170
constexpr const_reference back() const noexcept
Get a reference to the element at the top of the stack.
Definition stack.hpp:202
constexpr void push_back(Arg &&arg) noexcept
Push a new value to after the current top of the stack.
Definition stack.hpp:224
constexpr const_reference operator[](std::size_t index) const noexcept
Get a reference to an element on the stack at an index.
Definition stack.hpp:160
constexpr reference operator[](std::size_t index) noexcept
Get a reference to an element on the stack at an index.
Definition stack.hpp:150
constexpr void pop_back() noexcept
Remove the value at the top of the stack.
Definition stack.hpp:234
constexpr reference back() noexcept
Get a reference to the element at the top of the stack.
Definition stack.hpp:193
constexpr iterator begin() noexcept
Get an iterator to the first element on the stack.
Definition stack.hpp:69
constexpr size_type max_size() const noexcept
The maximum number of elements that fit on the stack.
Definition stack.hpp:117
constexpr const_reference at(std::size_t index) const noexcept
Get a reference to an element on the stack at an index.
Definition stack.hpp:182
constexpr const_iterator cbegin() const noexcept
Get an iterator to the first element on the stack.
Definition stack.hpp:85
constexpr void clear() noexcept
Remove all elements from the stack.
Definition stack.hpp:253