How to make delegate refer to itself?

H. S. Teoh hsteoh at quickfur.ath.cx
Sat Nov 23 14:57:18 PST 2013


How do I make a delegate refer to itself? I'm running into a
chicken-and-egg problem where a delegate needs to remove itself from an
event queue, but I don't know how to make it refer to itself:

	queue.register((Event e) {
		if (e == ...)
			queue.remove( /* ??? how to refer to self? */ );
	});

I tried this workaround but it still doesn't work:

	auto dg = (Event e) {
		if (e == ...)
			queue.remove(dg); // NG: Compiler complains 'dg' isn't defined
	};
	queue.register(dg);

I thought the auto was the problem, so I changed it to an explicit type,
but still no cigar:

	void delegate(Event) dg = (Event e) {
		if (e == ...)
			queue.remove(dg); // NG: Still complains 'dg' isn't defined
	};
	queue.register(dg);


T

-- 
Heuristics are bug-ridden by definition. If they didn't have bugs, they'd be algorithms.


More information about the Digitalmars-d-learn mailing list