Boost logo

Boost :

From: Yitzhak Sapir (yitzhaks_at_[hidden])
Date: 2002-06-18 08:47:41

Could you clarify what you mean by multiple arguments? I really hope that what I do now is semantically the same. Just to be sure, the following is a description of what I do and what I understood you meant.

I meant that I initialize the scoped_ptr directly from the auto_ptr. In other words, instead of:

scoped_ptr<T> sp(auto_pointer); // definitely at least syntactically nicer if not better semantics

I do:

scoped_ptr<T> sp(auto_pointer.release()); // same semantics?

In other words, I always call release() just before the constructor or reset() call of scoped_ptr.

If this is a one line declaration, I think it's fine. If it is initialized similarly with reset() it is fine.
If this is part of a constructor initializer list, I believe (but am not sure) that the release() function won't be evaluated until the member is to be initialized. So there won't be any throwing functions being called between release() and the constructor of scoped_ptr.

I'm not sure what you mean about multiple arguments, but I assume you mean that if I do something like:

class A { A(param1, param2, param3); }

and then do:

A(x, y.release(), z);

then y.release() breaks the ownership management until the constructor of A takes it over, in which case an exception may be thrown in between. But I think this would be true regardless of whether the constructor of scoped_ptr takes an auto_ptr or not.

> -----Original Message-----
> From: David Abrahams [mailto:david.abrahams_at_[hidden]]
> Sent: Tuesday, June 18, 2002 1:02 PM
> To: boost_at_[hidden]
> Subject: Re: [boost] Re: Conversion from auto_ptr to scoped_ptr?
> From: "Yitzhak Sapir" <yitzhaks_at_[hidden]>
> > > Bjorn wrote:
> > > It's bad because it introduces a dependency, without
> adding significant
> value (IMHO).
> >
> > Most of us don't change <memory> on a regular basis. So why is the
> dependency
> > problematic? What do you lose from it? I would like to
> have this, but
> for me, th
> > would be syntactic sugar, since I can accomplish the same thing with
> calling release()
> > before passing it to the constructor.
> That's not actually equivalent if you are passing multiple
> arguments. In
> case of an exception, the unmanaged memory may leak.
> I support the change to scoped_ptr.
> -Dave
> _______________________________________________
> Unsubscribe & other changes:

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