#include template class queue { private: struct node { std::shared_ptr data; std::unique_ptr next; }; std::unique_ptr head; node* tail; public: queue(): head(new node),tail(head.get()) {} queue(const queue& other)=delete; queue& operator=(const queue& other)=delete; std::shared_ptr try_pop() { if(head.get()==tail) { return std::shared_ptr(); } std::shared_ptr const res(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::shared_ptr new_data( std::make_shared(std::move(new_value))); std::unique_ptr p(new node); tail->data=new_data; node* const new_tail=p.get(); tail->next=std::move(p); tail=new_tail; } };