diff --git a/include/stack.h b/include/stack.h index de54ecb..65ca043 100644 --- a/include/stack.h +++ b/include/stack.h @@ -109,4 +109,14 @@ std::expected Stack::pop() { return std::expected(return_val); } +template +requires std::formattable +std::expected Stack::peek() { + if (this->len == 0) { + return std::unexpected(StackErr::empty); + } + + return std::expected(this->data[this->len - 1]); +} + #endif // !ST