Initializing a table of delegates with no-op stubs

H. S. Teoh hsteoh at quickfur.ath.cx
Mon Jan 20 19:45:18 UTC 2020


On Mon, Jan 13, 2020 at 11:43:22PM +0100, Rainer Schuetze via Digitalmars-d wrote:
> 
> 
> On 13/01/2020 19:06, H. S. Teoh wrote:
[.[..]
> > Mmm, very nice!  Kind of a weird paraphrasis, but at least it works.
> > To minimize hassle, I turned it into a template:
> > 
> > 	enum void delegate(Args) doNothing(Args...) = (Args args) {};
> > 
> > 	struct S {
> > 		void delegate(int x) dg1 = doNothing!(int);
> > 		void delegate(float y) dg2 = doNothing!(float);
> > 		void delegate(int x, int y) dg3 = doNothing!(int,int);
> > 	}
> > 
> > Do you think the first line is worth an addition to Phobos, maybe
> > alongside toDelegate?  It's non-obvious enough that it might save a
> > newbie (or a not-so-newbie like myself :-P) a lot of headache.
> > 
> 
> I think it's a bug in the compiler. If you can assign an enum value,
> why should the value itself not be good enough aswell?

Added info to the bug:

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


T

-- 
Why is it that all of the instruments seeking intelligent life in the universe are pointed away from Earth? -- Michael Beibl


More information about the Digitalmars-d mailing list