Suppose I have a Mutexed queue called MQueue:
#include <deque> template< typename T > class MQueue { public: T* pop() { lock(); T* ptr = nullptr; // get it out of m_dq... unlock(); return ptr; } // push, etc... and other methods private: std::deque<T*> m_dq; }; The following instantiation has been tested and works fine:
MQueue< int > my_simple_mq;
What kinds of modifications do I need to make to MQueue to ensure that
MQueue< std::unique_ptr< int > > my_smart_mq; will behave properly? I have attempted to browse the code to std::vector<> for reference, but it's difficult for me to discern which parts of the implementation are pertinent for the proper working of smart pointers. Any references or links would be greatly appreciated.
T*, and how? Do you wantT = unique_ptr<U>, or do you want to replaceT*byunique_ptr<T>?dequealready owns its contents), but maybe you'll find this article by Herb Sutter interesting.