www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 15427] New: dynamic casting functions should be available in


          Issue ID: 15427
           Summary: dynamic casting functions should be available in
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: druntime
          Assignee: nobody puremagic.com
          Reporter: ketmar ketmar.no-ip.org

it's sometimes useful to emulate dynamic casting in runtime having only
TypeInfo_Class at hands. now one has to rely on undocumented (and unexported)
`_d_dynamic_cast()` and friends, writing something like this:

// get druntime cast function
private extern(C) void* _d_dynamic_cast (Object o, ClassInfo c);

bool isCastable (Object O, TypeInfo_Class ti) {
  return (_d_dynamic_cast(o, ti) !is null);

it would be fine to introduce and use a documented API for that, like this:


i.e. we should add these methods to TypeInfo_Class. also, the same methods
should be added to TypeInfo_Interface.

Dec 08 2015