[Issue 15427] New: dynamic casting functions should be available in TypeInfo_Class

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Tue Dec 8 23:17:45 PST 2015


https://issues.dlang.org/show_bug.cgi?id=15427

          Issue ID: 15427
           Summary: dynamic casting functions should be available in
                    TypeInfo_Class
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: druntime
          Assignee: nobody at puremagic.com
          Reporter: ketmar at 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:

ti.dynamicCast(O)
ti.isBaseOf(O)


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

--


More information about the Digitalmars-d-bugs mailing list