#include template class queue { private: struct node { T data; std::unique_ptr next; node(T data_): data(std::move(data_)) {} }; std::unique_ptr head; node* tail; public: queue(): tail(nullptr) {} queue(const queue& other)=delete; queue& operator=(const queue& other)=delete; std::shared_ptr try_pop() { if(!head) { return std::shared_ptr(); } std::shared_ptr const res( std::make_shared(std::move(head->data))); std::unique_ptr const old_head=std::move(head); head=std::move(old_head->next); return res; } void push(T new_value) { std::unique_ptr p(new node(std::move(new_value))); node* const new_tail=p.get(); if(tail) { tail->next=std::move(p); } else { head=std::move(p); } tail=new_tail; } };