Boost logo

Boost :

From: Gustavo Guerra (gustavobt_at_[hidden])
Date: 2002-01-15 18:04:36

[Peter Dimov]
> As for release(), I think that it needs to be dropped.

[Robert Stewart]
> I recently created a special-purpose smart pointer that releases the ref
> count of something relying on a C API. I wanted to write my functions that
> return such pointers to return smart pointer objects to ensure that the
> count was decreased even if I simply ignored the return value of such
> functions. However, when returning to the calling C API, I needed to turn
> over the raw pointer in the return value, relinquishing ownership of it.
> do that, I call release() on my smart pointer class (which, based upon
> Andrei's insight, should be a non-member function).
> If I were using a Boost smart pointer without support for release(), how
> would I relinquish ownership()? That is, how do I tell the Boost smart
> pointer to not "deallocate" the pointer it holds, without release()?

After reading
I had this idea.

Why don't we drop get and release and instead put something like this:

class shared_ptr
  T* ptr;
  template<class F>
  void call_legacy_function(F callback)

Of course the callback could still do something bad with the pointer, but
it's more localized.

Just and idea
Gustavo Guerra

Boost list run by bdawes at, gregod at, cpdaniel at, john at