Boost logo

Boost :

Subject: [boost] Downcast taking account of virtual inheritance
From: vicente.botet (vicente.botet_at_[hidden])
Date: 2010-02-14 11:05:42


I have a generic class that needs to downcast from a base class to a template class. The template class can use virtual inheritance or not. When the derived class use virtual inheritance I need to use dynamic cast, but not on the other cases.

I'm wondering if a new downcast function that will take in account these facts would be of interest in Boost.

clase B {...};

class D : public B {...};

class DV : public virtual B {...};

B* ptr;
ptr= new D();
D* dPtr = downcast<D*>(ptr); // uses static_cast as is_virtual_base_of<B,D>::type is false

ptr= new DV();
DV* dPtr = downcast<DV*>(ptr); // uses dynamic_cast as is_virtual_base_of<B,DV>::type is true

What would be a good name for this downcast function?

Vicente Juan Botet Escribá

Boost list run by bdawes at, gregod at, cpdaniel at, john at