|
Boost : |
From: marchetti alessio (alessio_marchetti_at_[hidden])
Date: 2002-04-02 03:01:17
hi,
I was looking at usage patterns of the shared_ptr
template and noticed that most of the times it only
makes sense to create smart pointer objects from
un-named (temporaries) naked pointers:
shared_ptr<int> cp (new int);
The following idiom creates confusion (the ip variable
is not used after the ctor call):
int * ip = new int;
shared_ptr<int> cp ( ip );
The first idiom promotes better encapsulation: do you
think that forcing this usage patterns through
interface would make sense?
It's possible to do that by changing the ctor:
explicit shared_ptr(T * p = 0): px(p), pn(p,
deleter())
{
}
to
explicit shared_ptr(T * const &p = 0): px(p),
pn(p, deleter())
{
}
and by adding an additional dummy ctor:
explicit shared_ptr(T * &p): px(p), pn(p,
deleter())
{
shared_ptr_ctor_needs_temporary_actual_parameter;
}
This change of course breaks source compatibility...
Alessio Marchetti
__________________________________________________
Do You Yahoo!?
Yahoo! Tax Center - online filing with TurboTax
http://http://taxes.yahoo.com/
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk