Boost logo

Boost :

From: Sohail Somani (s.somani_at_[hidden])
Date: 2006-12-01 15:32:40


> -----Original Message-----
> From: boost-bounces_at_[hidden]
> [mailto:boost-bounces_at_[hidden]] On Behalf Of Tobias Schwinger
> Sent: Friday, December 01, 2006 12:17 PM
> To: boost_at_[hidden]
> Subject: Re: [boost] FW: Suggestion for boost`s smart pointers
>
> Sohail Somani wrote:
> > Thanks for your reply but the domain of COM objects lends
> itself well to shared_ptr.
>
> As to scoped_ptr. I don't quite understand the "but" in that sentence.

Agreed. But something that applies to scoped_ptr + deleter doesn't
always apply to shared_ptr.

> > I went through the archives after the posts and I have
> realized that
> > scoped_ptr is not changing! I will still disagree that the
> deleter shouldn't
> > be a parameterized type.
>
> What's wrong with:
>
> template<typename T> void free_resource(T* ptr)
> { delete ptr; }
> void free_resource(std::FILE* f)
> { std::fclose(f); }
> void free_resource(IDispatch * o)
> { o->Release(); }
>
> template<typename T>
> struct scoped_ptr
> {
> // [...]
> ~scoped_ptr() { free_resource(this->p_); }
> // [...]
> };
>

I don't particularly like requiring implicit function declarations. I'd
rather tie them to the resource pointer type somehow. That's just my own
preference which may or may not be totally wrong (but its not). I think
its too easy for people to forget to do it. I prefer parameterized type
+ typedef.

> > The only other option is using a type erasure mechanism
> like shared_ptr which
> > is more trouble than its worth for things like deallocating
> C resources.
>
> I was referring to the file pointer, which is pretty much the
> only "C resource" I use.
> You're right when it comes to malloc/free, of course - but do
> we really need it?

Anytime you deal with C atleast, the answer is yes.

Sohail


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk