Boost logo

Boost :

From: Dave Abrahams (abrahams_at_[hidden])
Date: 2000-03-20 22:17:28

on 3/20/00 9:23 AM, Borgerding, Mark A. at MarkAB_at_[hidden] wrote:

> I sent an example on Saturday of the behavior I fear most from operator T*
> My concern involves automatic conversion of smart ptrs as return values.

Ah, yes, I remember now. It's a good example. At the time I didn't pay much
attention because I wasn't willing to give an implicit conversion the time
of day anyhow. ;)

> I have had a couple more days to examine my beliefs and concerns, as well as
> those of list members with differing viewpoints. It looks like the danger
> might be limited by a small change to the smart ptr interface and sufficient
> programmer discipline.
> Small Change:
> shared_ptr operator T* changed from
> operator T*() const throw() { return ptr; }
> to
> operator T*() throw() { return ptr; }
> Programmer Discipline:
> Make functions return
> const shared_ptr<foo>
> instead of
> shared_ptr<foo>
> If both of the above are true, then the problem case would not compile.


> I'm not thrilled about a solution that requires extra discipline on the part
> of the user, but I guess I could live with it.

I sense we're about to enter auto_ptr_ref land. Stop! Stop!!! Noooooooooo!

I must say I find Mark's example rather convincing.


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