$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
From: Greg Colvin (gcolvin_at_[hidden])
Date: 2001-07-24 15:49:07
From: Peter Dimov <pdimov_at_[hidden]>
> From: "Greg Colvin" <gcolvin_at_[hidden]>
> [...]
> 
> >     template<typename BasePtr, typename DerivedPtr>
> >     DerivedPtr whatever(BasePtr in) {
> >        ...
> >        DerivedPtr p = do_dynamic_cast<DerivedPtr>(in);
> >        ...
> >        return p;
> >     }
> 
> Or something like
> 
> template<class Ptr> void whatever(Ptr p)
> {
>    if(IDrawable q = do_dynamic_cast<IDrawable>(p)) q->draw();
> }
> 
> where IDrawable is typedef'ed somewhere to be, say, shared_ptr<Drawable>.
> 
> (As an aside, people like to implement their own COM-like component systems;
> it would be great if shared_ptr<> can be used for this. The two main
> obstacles are (1) no 'queryInterface' support - this would hopefully be
> addressed by do_dynamic_cast - and (2) a shared_ptr<> created in a DLL and
> destroyed in the main program causes problems when different heaps are
> used.)
I have a version of shared_ptr with a parameterized deleter that
could handle this problem, but I haven't had time to get it ready
for posting.
> Still, I prefer that shared_dynamic_cast<> be left as an option. More
> focused (less generic) interfaces are less error prone, when genericity is
> not required.
Yes, although I think a shared_ptr member function is the right
way to go for that purpose.