...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::scoped_ptr
// In header: <boost/interprocess/smart_ptr/scoped_ptr.hpp> template<typename T, typename Deleter> class scoped_ptr { public: // types typedef T element_type; typedef Deleter deleter_type; typedef unspecified pointer; typedef pointer this_type::* unspecified_bool_type; // construct/copy/destruct scoped_ptr(const pointer & = 0, const Deleter & = Deleter()); ~scoped_ptr(); // public member functions void reset(const pointer & = 0) ; void reset(const pointer &, const Deleter &) ; pointer release() ; reference operator*() const; pointer & operator->() ; const pointer & operator->() const; pointer & get() ; const pointer & get() const; operator unspecified_bool_type() const; bool operator!() const; void swap(scoped_ptr &) ; };
scoped_ptr stores a pointer to a dynamically allocated object. The object pointed to is guaranteed to be deleted, either on destruction of the scoped_ptr, or via an explicit reset. The user can avoid this deletion using release(). scoped_ptr is parameterized on T (the type of the object pointed to) and Deleter (the functor to be executed to delete the internal pointer). The internal pointer will be of the same pointer type as typename Deleter::pointer type (that is, if typename Deleter::pointer is offset_ptr<void>, the internal pointer will be offset_ptr<T>).
scoped_ptr
public
construct/copy/destructscoped_ptr(const pointer & p = 0, const Deleter & d = Deleter());Provides the type of the internal stored pointer.
Constructs a scoped_ptr, storing a copy of p(which can be 0) and d. Does not throw.
~scoped_ptr();
If the stored pointer is not 0, destroys the object pointed to by the stored pointer. calling the operator() of the stored deleter. Never throws
scoped_ptr
public member functionsvoid reset(const pointer & p = 0) ;
Deletes the object pointed to by the stored pointer and then stores a copy of p. Never throws
void reset(const pointer & p, const Deleter & d) ;
Deletes the object pointed to by the stored pointer and then stores a copy of p and a copy of d.
pointer release() ;
Assigns internal pointer as 0 and returns previous pointer. This will avoid deletion on destructor
reference operator*() const;
Returns a reference to the object pointed to by the stored pointer. Never throws.
pointer & operator->() ;
Returns the internal stored pointer. Never throws.
const pointer & operator->() const;
Returns the internal stored pointer. Never throws.
pointer & get() ;
Returns the stored pointer. Never throws.
const pointer & get() const;
Returns the stored pointer. Never throws.
operator unspecified_bool_type() const;
Conversion to bool Never throws
bool operator!() const;
Returns true if the stored pointer is 0. Never throws.
void swap(scoped_ptr & b) ;
Exchanges the internal pointer and deleter with other scoped_ptr Never throws.