Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2001-04-05 12:30:03

From: "David Abrahams" <abrahams_at_[hidden]>

> From: "Peter Dimov" <pdimov_at_[hidden]>

> > AFAIK auto_ptr_ref supports passing/returning auto_ptrs by value. I
> > that this is unnecessary for boost::auto_ptr, since (1) we have
> > boost::shared_ptr for this, (2) passing auto_ptrs by value instead of
> > non-const reference is dangerous (exception safety), and (3) returning


> I strongly disagree with this. My coding standard says "always pass
> by value". Why? When I see auto_ptr<...> in a piece of code, I think
> "transfer of ownership is happening here". Passing auto_ptr by const
> reference undermines that meaning.

See above. :-)

> If you are going to pass by const
> reference, you might as well call get() and pass a raw pointer, anyway.
> Passing an auto_ptr by value (or by non-const reference) is the only way
> transfer ownership into a function. I really prefer the former, because it
> makes the meaning absolutely unambiguous (ownership is definitely given
> away).

Yes, you have a point. A non-const reference is ambiguous, it can be a
return value as well. I won't suddenly start passing auto_ptrs by value, but
I see the point.

> What are the exception-safety problems that you allude to?

See my other post.

Peter Dimov
Multi Media Ltd.

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