$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
From: greg_at_[hidden]
Date: 2001-07-23 23:08:53
I sent this hours ago, but it hasn't shown up, so I'll try again.
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.  And it 
would still be good to have a polymorphic_cast for shared_ptr.  Must 
doing so really create dependencies?
From: <martinschuerch_at_[hidden]>
> ...
> >  >> Sounds like a plan.
> >  >
> >  >I would very appreciate some downcast of shared_ptr in boost.
At 
> the
> >  >moment I'm using a hack similar as posted in related mails. But 
> for a
> >  >proper solution there has to be some support of shared_ptr.
> >  >
> >  >Is there any work in progress for this subject?
> > 
> > Why don't you post suggested code?
> > 
> > --Beman
> 
> 
> So here it is:
> 
> The template function shared_dynamic_cast<> delegates the work to 
the 
> memberfunction 
> 
> template<class Q>
> void downcasted_copy_to( shared_ptr<Q>& q ) const
> 
> that way no friend is used. VC would not support the partial 
> specialization (or is it overloading I never know) of 
> polymorphic_downcast<> and I like shared_ptr and the downcast to be 
> an unit without dependencies.
> The suggested code isn't optimized for speed.
> 
> 
> Member-template:
> 
> template<class Q>
> void downcasted_copy_to( shared_ptr<Q>& q ) const
> {
> Q* rawq = dynamic_cast<Q*>(px);
> if( !rawq || !px ) { q = shared_ptr<Q>(); }
> shared_ptr<Q> ptmp;
> ptmp.px = rawq;
> ++*pn;
> ptmp.pn = pn;
> q.swap( ptmp );
> }
> 
> "global" function:
> 
> template<class Tout,class Tin>
> boost::shared_ptr<Tout> shared_dynamic_cast( 
>                          const boost::shared_ptr<Tin>& p )
> {
> boost::shared_ptr<Tout> pout;
> p.downcasted_copy_to(pout);
> return pout;
> }
> 
> int test_main( int, char *[] )  // note the name!
> {
> using namespace boost;
> 
> shared_ptr<Base> pb( new Base );
> shared_ptr<Base> pb2d( new Derived );
> // shared_ptr<Derived> pd( new Derived );
> shared_ptr<Derived> pd;
> 
> pd = shared_dynamic_cast<Derived>(pb2d);
> pd->print();
> pd = shared_dynamic_cast<Derived>(pb);
> BOOST_CRITICAL_TEST( pd == shared_ptr<Derived>()  );
> 
> return 0;
> }
> 
> Thanks for feedback
> Martin
> 
> 
> 
> 
> Info: http://www.boost.org  Unsubscribe: 
<mailto:boost-unsubscribe_at_[hidden]> 
> 
> Your use of Yahoo! Groups is subject to 
http://docs.yahoo.com/info/terms/ 
> 
> 
>