|
Boost : |
From: Fernando Cacciola (fcacciola_at_[hidden])
Date: 2001-07-24 13:08:10
----- Original Message -----
From: Greg Colvin <gcolvin_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Tuesday, July 24, 2001 12:34 PM
Subject: Re: [boost] Re: downcasting smart pointers (suggested code)
> From: Peter Dimov <pdimov_at_[hidden]>
> > From: <greg_at_[hidden]>
> > > This looks like a good start, thanks. I think do_dynamic_cast is the
> > > name we previously agreed on for your shared_dynamic_cast, and that
> > > we wanted a version that worked for raw pointers as well.
> >
> > If do_dynamic_cast is supposed to be a generalization of dynamic_cast:
> >
> > template<class R, class T> R do_dynamic_cast(T /* const */ &);
> >
> > (dynamic_cast<U*> returns U*, dynamic_cast<U&> returns U&)
> >
> > then dynamic-casting a shared_ptr would look like
> >
> > do_dynamic_cast<shared_ptr<X> >(y); // 1
> >
> > whereas with a shared_ptr-specific cast the syntax would be
> >
> > shared_dynamic_cast<X>(y); // 2
> >
> > I prefer (2). (1) is more generic but I can't see how the genericity
would
> > be exploited.
>
> It could be exploited in generic code that didn't care whether
> it was operating on raw pointers or smart pointers?
Hmmm. I'm not sure if this is a desired behaviour.
It is well known that mixing shared_ptr<T> and T* can lead to unexpected
behavior. You have to do that carefully.
Just as I like not being able to cast a shared_ptr<T> to a T* (I call get()
if I really need to), I don't think I'd like a common
interface to downcasting pointers.
Don't get me wrong, I do support genericity as mush as possible, but in this
area I'm not sure if both types can be generalized this much.
Fernando Cacciola
Sierra s.r.l.
fcacciola_at_[hidden]
www.gosierra.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk