I don't see how to get scoped_ptr or scoped_array to use a custom deleter. Maybe there is another implementation which allows controlled deletion similar to shared_ptr?
Btw, why does shared_ptr allow custom deleter but scoped_ptr doesn't? Just curious.
I don't see how to get
scoped_ptr
orscoped_array
to use custom deleter
You can't.
Maybe there is another implementation which allows controlled deletion similar to
shared_ptr
?
If your compiler supports rvalue references and your Standard Library implementation implements std::unique_ptr
, you can use that.
Otherwise, the boost::scoped_ptr
implementation is very straightforward. The latest version is less than 100 lines of simple code. It would be quite simple to create your own derivative that has a custom deleter (either a static via a template parameter or dynamic via a function or functor provided at runtime).
scoped_ptr
doesn't allow custom deleter. The main reason as I can suppose is that its' size will not be equal to sizeof(T*)
if it would keep a boost::function<>
as shared_ptr
does.
I think the most portable options are to use shared_ptr
or to write your own scoped_ptr
that will support deleters.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With