Boost logo

Boost Users :

Subject: [Boost-users] [shared_ptr] deleter that destroys shared_ptr - is it safe?
From: Igor R (boost.lists_at_[hidden])
Date: 2009-09-08 17:28:21


Hello,

Is the following code legal and safe -
a) according to the shared_ptr specs
b) with the current boost::shared_ptr implementation

Thanks!

struct a
{
  a() : p_(this, mem_fn(&a::delete_me))
  {}
  void reset()
  {
    p_.reset();
  }
  void delete_me()
  {
    delete this;
  }

  shared_ptr<a> p_;
};

int main()
{
  a* p = new a;
  p->reset();
}


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