On 2019-07-03 19:07:10 +0000, ag0aep6g said:
On 03.07.19 20:20, Robert M. Münch wrote:
So, I need to carry around the object from which a delegate was created
from because it's not possible to query the delegate for the object
later somewhere else in the code.
It is possible to get the context object out of a delegate:
----
class C { void method() {} }
void main()
{
auto c = new C;
void delegate() dg = &c.method;
assert(cast(C) dg.ptr is c); /* passes */
}
----
You just have to know (or carry around) the type so that you can cast
correctly.
Hmm... IIRC I once played around and it didn't work... seems I messed
this up. Thanks for correcting my wrong perception here.
--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster