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