|
Boost Users : |
From: Maitre Bart (maitrebart_at_[hidden])
Date: 2006-11-29 11:45:51
Sohail Somani <s.somani <at> fincad.com> writes:
> [...]
> template<typename T>
> struct DeletingDeleter
> {
> [...]
> };
>
> struct FileCloser
> {
> [...]
> };
>
> template<typename T, typename Deleter=DeletingDeleter<T> >
> struct scoped_ptr
> {
> [...]
> };
>
> typedef scoped_ptr<FILE,FileCloser> file_ptr;
I also tried to make my own raii strategy, and as in your example above, I put
the deleter as part of the template parameters, directly in the smart pointer
interface.
The side effect of it is that if you use a boost binder that on its turn uses
one or more template functions or classes, you end up with many lines to
describe the template specializations (or call it "template prototyping"), or
as in your case, many lines of extra structure and classes. (I wished the
new "auto" feature in C++0x existed!)
Still, the method used by shared_ptr<> is very useful: it hides the deleter in
a template class the derives from a normal base class that is a member of the
shared_ptr<>. So when you defines the smart pointer with a deleter, you avoid
describing the full specialization.
That is the reason why I suggested to reuse the shared_ptr<> astuce in
scoped_ptr<>.
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