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
ref
> 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.
To
> 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
http://groups.google.com/groups?q=g:thl1602934015d&hl=en&selm=3C3990CE.93B75
728%40oxyware.com
I had this idea.

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

template<T>
class shared_ptr
{
private:
  T* ptr;
public:
  template<class F>
  void call_legacy_function(F callback)
  {
    callback(ptr);
  }
};

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 acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk