#include <toast/unintrusive_ptr.hpp>
This templated class is a smart pointer type that maintains a reference count for the object it points to. Its interface is slightly different from most smart pointers in that it requires you to pass an in place factory to its constructor instead of a pointer to an already allocated object. This is because it creates the object in place adjacent to its reference count in memory. This allows the performance benefits of an intrusive smart pointer without being intrusive. In Boost 1.39+ you can use make_shared to get similar benefits with shared_ptr, but a shared_ptr will still be twice as large and have a less safe interface (unintrusive_ptr construct their contents via factories so that it's guaranteed they manage the object).
unintrusive_ptr will do its best to detect if you are violating the previous warning. It adds cheap startup checks to determine if any templates were instantiated for base class pointers to derived class objects with MI in their hierarchy. However, there is one case it will not catch, which is if a derived object is pointed to by a base class pointer where the base class is the first class in list of the derived class's bases. unintrusive_ptr will actually work correctly in this situation! However, since this usage might create the expectation that unintrusive_ptr will work with other bases (which it won't) we suggest against doing this intentionally.
Public Types | |
typedef T | element_type |
typedef T *(unintrusive_ptr< T >::* | unspecified_bool_type )() const |
Public Member Functions | |
template<class TypedInPlaceFactory> | |
unintrusive_ptr (TypedInPlaceFactory const &factory) | |
unintrusive_ptr (unintrusive_ptr const &toCopy) | |
template<class Y> | |
unintrusive_ptr (unintrusive_ptr< Y > const &other) | |
template<class Y> | |
unintrusive_ptr (weak_unintrusive_ptr< Y > const &r) | |
unintrusive_ptr & | operator= (unintrusive_ptr const &target) |
template<class Y> | |
unintrusive_ptr< T > & | operator= (unintrusive_ptr< Y > const &target) |
void | reset () |
template<class TypedInPlaceFactory> | |
void | reset (TypedInPlaceFactory const &factory) |
T & | operator* () const |
T * | operator-> () const |
T * | get () const |
operator unspecified_bool_type () const | |
void | swap (unintrusive_ptr< T > &other) |
Friends | |
class | unintrusive_ptr |
class | weak_unintrusive_ptr< T > |
template<class Y> | |
int | detail::get_use_count (unintrusive_ptr< Y > const &x) |
template<class Y> | |
bool | detail::get_unique (unintrusive_ptr< Y > const &x) |
template<class X, class Y> | |
unintrusive_ptr< X > | static_pointer_cast (unintrusive_ptr< Y > const &r) |
template<class X, class Y> | |
unintrusive_ptr< X > | const_pointer_cast (unintrusive_ptr< Y > const &r) |
template<class X, class Y> | |
unintrusive_ptr< X > | dynamic_pointer_cast (unintrusive_ptr< Y > const &r) |
template<class X, class Y> | |
bool | operator== (unintrusive_ptr< X > const &a, unintrusive_ptr< Y > const &b) |
template<class X, class Y> | |
bool | operator!= (unintrusive_ptr< X > const &a, unintrusive_ptr< Y > const &b) |
template<class X, class Y> | |
bool | operator< (unintrusive_ptr< X > const &a, unintrusive_ptr< Y > const &b) |