parameterized lazy expression
freeagle
dalibor.free at gmail.com
Wed Oct 3 02:40:34 PDT 2007
Daniel Keep Wrote:
>
>
> 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
thanks Daniel
More information about the Digitalmars-d-learn
mailing list