...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
boost::interprocess::enable_shared_from_this
// In header: <boost/interprocess/smart_ptr/enable_shared_from_this.hpp> template<typename T, typename A, typename D> class enable_shared_from_this { public: // construct/copy/destruct enable_shared_from_this(); enable_shared_from_this(enable_shared_from_this const &); enable_shared_from_this& operator=(enable_shared_from_this const &); ~enable_shared_from_this(); // public member functions shared_ptr< T, A, D > shared_from_this(); shared_ptr< T const, A, D > shared_from_this() const; mutable weak_ptr< element_type, A, D > _internal_weak_this; // @ typedef T element_type; };
This class is used as a base class that allows a shared_ptr to the current object to be obtained from within a member function. enable_shared_from_this defines two member functions called shared_from_this that return a shared_ptr<T> and shared_ptr<T const>, depending on constness, to this.
enable_shared_from_this
public
construct/copy/destructenable_shared_from_this();@ protected:
enable_shared_from_this(enable_shared_from_this const &);
enable_shared_from_this& operator=(enable_shared_from_this const &);
~enable_shared_from_this();
enable_shared_from_this
public member functionsshared_ptr< T, A, D > shared_from_this();
shared_ptr< T const, A, D > shared_from_this() const;