|
Boost : |
From: Frank Mori Hess (frank.hess_at_[hidden])
Date: 2008-04-17 09:23:48
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Thursday 17 April 2008 01:42 am, Daniel Frey wrote:
> On Wed, 2008-04-16 at 17:16 -0400, Frank Mori Hess wrote:
> > > Daniel Frey:
> > > template< typename U >
> > > shared_ptr<U> shared_from_this( U* u );
> > >
> > > template< typename U >
> > > shared_ptr<U const> shared_from_this( U const* u );
> >
> > Wouldn't it be safer to make it a non-template? The aliasing constructor
> > can be easily misused. If the user really wants to use the aliasing
> > constructor, they could always pass the return value from
> > shared_from_this() to the aliasing constructor.
>
> In which case it is useless, as it cannot accept "this" and therefore
> doesn't solve any problem at all. Passing this allows you to pass the
> type of "this", which is the derived type T, not the type of
> enable_shared_from_this<T>.
No, what I was trying to convey is you have the T type inside
enabled_shared_from_this<T>. To be clear:
template<typename T>
enable_shared_from_this
{
shared_ptr<T> shared_from_this(T *t);
//...
};
Whether you remove the template parameter from the shared_from_this method, or
or follow Peter's suggestion and remove it from enable_shared_from_this
class, it seems like you have one more template than you need.
Also, there is no reason not to add a simple helper free function:
template<typename T>
shared_ptr<T> shared_from_this(T *t)
{
return t->shared_from_this(t);
}
which would provide some convenience and a sanity check for the common case
usage.
- --
Frank
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
iD8DBQFIB09q5vihyNWuA4URAsk4AJ9XMFrEZCYA/y/6ujGQM0SxoJTmIwCdErKS
DjD2nFRshjUQl/3HRjwLEVA=
=dSld
-----END PGP SIGNATURE-----
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk