I'm a little confused about boost's intrusive pointer. The definition says:
"Every newinstance increments the reference count by
using an unqualified call to the function,
passing it the pointer as an argument. Similarly, when an
is destroyed, it calls
function is responsible for destroying the object when its reference
count drops to zero. The user is expected to provide suitable
definitions of these two functions. "
You have to provide these functions. This is how
Let's compare it with
shared_ptr manages the reference count itself in the control block associated with the pointee. Creating a
shared_ptr increments the refcount. Destroying a
shared_ptr decrements the refcount. When the refcount goes to 0, the pointee is destroyed.
intrusive_ptr works in exactly the same way, but does not manage the reference count itself. It just signals to its client "now the refcount must be incremented" and "now the refcount must be decremented." It does that by calling the two functions mentioned,
intrusive_ptr_release. If you do not define them, you will get a compilation error.
Think of these functions as the interface to the reference counter. Using
intrusive_ptr indicates that the refcount is managed somewhere outside the pointer (usually in the pointee itself), and the pointer just intrudes on that refcount, using it for its purposes.