25 constexpr undo_stack(
size_t max_depth) noexcept : _stack{}, _max_depth(max_depth), _cursor(0) {}
27 template<
typename... Args>
28 constexpr void emplace(Args &&... args)
noexcept
30 push(value_type{std::forward<Args>(args)...});
33 [[nodiscard]]
constexpr bool can_undo()
const noexcept
38 template<
typename... Args>
39 [[nodiscard]]
constexpr value_type
const &undo(Args &&...args)
noexcept
41 hi_assert(can_undo());
45 push(value_type{std::forward<Args>(args)...});
50 return _stack[--_cursor];
53 [[nodiscard]]
constexpr bool can_redo()
const noexcept
55 return (_cursor + 1) < _stack.size();
58 [[nodiscard]]
constexpr value_type
const &redo()
const noexcept
60 hi_assert(can_redo());
61 return _stack[++_cursor];
67 mutable size_t _cursor;
68 mutable bool _first_undo =
true;
70 template<forward_of<value_type> Value>
71 constexpr void push(Value &&value)
noexcept
73 hi_assert(_cursor <= _stack.
size());
76 if (_stack.
size() > _max_depth) {
80 _stack.
push_back(std::forward<Value>(value));
81 _cursor = _stack.
size();