|
Boost : |
From: Andrei Alexandrescu (andrewalex_at_[hidden])
Date: 2003-01-29 23:42:44
"David Abrahams" <dave_at_[hidden]> wrote in message
news:uadhj9vne.fsf_at_boost-consulting.com...
[snip]
One problem I see is that the constructor uses a different syntax than any
other function. Imho syntax uniformity is good, and lack thereof is not
good.
Other languages get away from this problem by considering the first
assignment to an base or member, the constructor call for that base or
member. If no first assignment is statically decided, there is a
compile-time error.
If that were the case, Loki::SmartPtr's constructor could be written like
this:
SmartPtr::SmartPtr(T* p)
{
*this = storage(p);
ScopeGuard g = MakeGuard(storage::destroy, p);
*this = ownership(p);
g.Dismiss();
*this = conversion();
*this = checking();
}
Well, dream mode off. If that's not to work, using Dave Abrahams' idea of
passing a default argument might apply, however the problem is that you
can't pass previous arguments to the default argument :o/.
I suggest we just make an explicit function acquire() for the ownership
policy and have all of its other member functions assume acquire() was
called.
Imho this is an issue of language peculiarity, and not a matter of
principle.
Andrei
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk