Boost logo

Boost :

From: Miki Jovanovic (miki_at_[hidden])
Date: 2000-02-08 10:28:31


Hello all,

Here is my proposition for dynamic_cast for shared_ptr. Would this be
of value?

public:
   template<typename Y> shared_ptr& dynamiccast( const shared_ptr<Y>& r
) {
      if ( pn != r.pn ) {
         dispose();

         dynamicShare( r.px, r.pn );
      }
      return *this;
   }

protected:
   template<typename Y> void dynamicShare( Y* rpx, long* rpn ) {
      Y *cast_rpx = dynamic_cast<T*>( rpx );
      if ( rpx == NULL || cast_rpx != NULL ) { // check to avoid new()
for NULL objects. too much?
         px = rpx;
         ++*(pn = rpn);
      }
      else { // dynamic_cast failed
         px = NULL;
         pn = new long(1);
      }
   }

Cheers,

Miki Jovanovic.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk