parameterized lazy expression

Daniel Keep daniel.keep.lists at gmail.com
Tue Oct 2 19:47:28 PDT 2007



freeagle wrote:
> hmm, well, if thats the shortest possible form...
> 
> i wanted to make a template representing mathematical sets, that would
> be defined something like MSet!(int)(x > 0 && x < 10, x*2)
> but with the returns and all, it looks weird:
> MSet!(int)((int x) {return x > 0 && x < 10; }, (int x) { return x * 2; })
> 
> freeagle

You could always use something like this:

MSet!(int, "$ > 0 && $ < 10", "$ * 2");

Then use CTFE to replace the '$' with whatever symbol it uses
internally, and then string mixin the result.

Not *quite* as clean as you wanted, but at least there aren't any nasty
delegate literals!

	-- Daniel


More information about the Digitalmars-d-learn mailing list