How would You make abstract HANDLE?

Mariusz Gliwiński alienballance at gmail.com
Wed Jan 19 04:27:40 PST 2011


How to make a HANDLE in D without casting and stuff:
<code>
interface iface{
     void doSomething(HANDLE h);
}
class A : iface {
     override void doSomething(HANDLE h) {
         assert(validPointer(h));
         h.foo = bar;
     }
}
class B : iface {
     someVar table[];
     override void doSomething(HANDLE h) {
         assert(table.isInBounds(h));
         table[h].foo = bar;
}
</code>

Module/class -scoped alias would be great like:
<code>
#a.d
private alias uintptr_t HANDLE;

#b.d
private alias someVar HANDLE;
</code>

but alias is resolved too early for that. How to make it properly then? 
Union or something else?

Thanks,
Mariusz Gliwiński


More information about the Digitalmars-d-learn mailing list