Boost Users :
From: Peter Dimov (pdimov_at_[hidden])
Date: 2006-05-02 07:29:59
Scott Meyers wrote:
> Suppose I have an auto_ptr, shared_ptr, or scoped_ptr. If I want to
> set it to null, I do this (assuming the pointer is named p):
> p.reset(); // okay
> If I try this,
> p = 0; // error
> I get an error during compilation. In other words, reset works, but
> assignment of the null pointer does not.
> But suppose p is an intrusive_ptr. Now
> p.reset(); // error
> fails, and
> p = 0; // okay
> succeeds. In other words, assignment works, but reset does not. I
> find this, er, unintuitive. Does anybody know why intrusive_ptr
> marches to its own nullifying drummer?
The reason for p = 0 working in intrusive_ptr's case is that intrusive_ptr
has an assignment operator taking a raw pointer. The other smart pointer
types do not.
The lack of intrusive_ptr::reset is arguably a defect in intrusive_ptr's
interface. My personal opinion is that moving between shared_ptr and
intrusive_ptr doesn't have to be smooth because their semantics are
different enough to warrant a careful code review after the switch. On the
other hand, consistency does have its benefits.
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net