On 2014-01-23 23:51, Martin Nowak wrote:
Wouldn't it be possible to find out whether the delegate context ptr
is actually an object? Not sure how to do it safely though and
Interfaces slightly differ.
```d
import std.stdio;
class Foo
{
void method() {}
}
void main()
{
auto foo = new Foo;
auto dg = &foo.method;
// It's a class delegate!!!
writeln(cast(void*)foo.classinfo.__vptr, " ",
***cast(void****)dg.ptr, " ", (new ClassInfo).__vptr);
assert(***cast(void****)dg.ptr is (new ClassInfo).__vptr);
}
```
Why don't you just cast the delegate context pointer to Object? Like this:
auto result = cast(Object) dg.ptr;
If "result" is not null the context pointer points to an object.
Although this won't handled interfaces. I consider it a bug that an
interface cannot be casted to Object.
--
/Jacob Carlborg