21 constexpr undo_stack(undo_stack
const &)
noexcept =
default;
22 constexpr undo_stack(undo_stack &&)
noexcept =
default;
23 constexpr undo_stack &operator=(undo_stack
const &)
noexcept =
default;
24 constexpr undo_stack &operator=(undo_stack &&)
noexcept =
default;
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
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());
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());
74 _stack.erase(_stack.begin() + _cursor, _stack.end());
76 if (_stack.size() > _max_depth) {
77 _stack.erase(_stack.begin());
81 _cursor = _stack.size();