Static cast

Jason House jason.james.house at gmail.com
Wed Jun 25 15:53:54 PDT 2008


&BCS Wrote:

> Reply to Jason,
> 
> > What is the proper way to implement static cast?
> > 
> > cast(T) to shift with an object/ interface hierarchy is dynamic and
> > slow. My problem is that cast(T)cast(void*) does not honor vtable
> > locations and ClassInfo is only available at runtime.
> > 
; 
> up cast or down cast?

Both. Upcasting to an interface shows up in my profiler. 
 
> IIRC upcast /is/ non-dynamic and skipping the test on downcast is just a 
> bad idea.

I've implemented algorithms to operate on interfaces. Operations called by the algorithm require casting. All the data operated on by an algorithm is the same type. In this case, it's safe and will speed up execution by at least 15%


More information about the Digitalmars-d-learn mailing list