|
Boost : |
From: Milutin Jovanovic (miki_at_[hidden])
Date: 2000-08-22 08:03:45
From: "David Abrahams" <abrahams_at_[hidden]>
> 1. noncopyable can be used when no sensible copy semantics exist. There is
> simply no analogue for dynamic construction. If it makes sense to write
> X x;
> then it also makes sense to say
> std::auto_ptr<X> x(new X);
Until recently I did not see much use for it, but we have a concrete example
in our thread conversations. The mutex_lock class that locks a mutex only
within a scope should not be allowed to exist on heap and that way keep the
lock outside of scopes. Object stored in your auto_ptr can very legaly
survive past the end of your scope.
> 2. noncopyable prevents copying even when the type in question is a
> subobject. nonnewable can't prevent dynamic allocation as a subobject.
True, but the writer of the subclass takes responsibility for that. Yes, it
opens a door for workarounds, but at least you warned (strongly) the user.
Cheers,
Miki Jovanovic.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk