#ifndef CORE_STACK_HPP #define CORE_STACK_HPP #include "data/ArrayList.hpp" #include "data/List.hpp" namespace Core { namespace Internal { template class BaseStack final { S data{}; public: template check_return Error push(Args&&... args) { return data.add(Core::forward(args)...); } void clear() { data.clear(); } check_return Error pop() { return data.removeBySwap(data.getLength() - 1); } bool isEmpty() const { return data.getLength() == 0; } T& peek() { return data[data.getLength() - 1]; } const T& peek() const { return data[data.getLength() - 1]; } template check_return Error toString(String& s) const { return s.append(data); } }; } template using ListStack = Internal::BaseStack>; template using ArrayStack = Internal::BaseStack>; } #endif