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


Hi,

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?

Best,
_____________________
Vicente Juan Botet Escribá


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