#ifndef stack_h #define stack_h 1 #include template class stack { public: using empty = std::exception; stack(): head(nullptr) {} ~stack() { while (head) pop(); } void push(const T& t) { atomic_noexcept { head = new node{head, t}; } } T pop() { atomic_noexcept { if (head) { node* n = head; head = head->next; T t = n->data; delete n; return t; } } throw empty(); } private: struct node { node* next; T data; }; node* head; }; #endif // stack_h