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