#ifndef stack_h #define stack_h #include // std::unique_ptr #include // std::optional template class stack { public: ~stack() { while (pop()); } void push(T t) { head = std::make_unique(std::move(head), t); } std::optional pop() { if (head) { T data = head->data; head = std::move(head->next); return std::optional(data); } else { return std::nullopt; } } private: struct node { std::unique_ptr next; T data; }; std::unique_ptr head = nullptr; }; #endif // stack_h