Proposal to add 'Elements of Programming' Concepts to std.traits

Guillaume Chatelet chatelet.guillaume at gmail.com
Sun Jun 17 07:54:16 PDT 2012


On 06/17/12 15:53, Philippe Sigaud wrote:
> x => ... still has some problem as it's a template, but using a
> standard module-level function gives functionalities akin to X10:
> 
> bool pos(int x) { return x > 0;}
> alias Constrained!(int, pos) Positive; // works
> 
> // alias Constrained!(int, (int x) { return x > 0;}) Positive; // works
> // alias Constrained!(int, (int x) => x > 0) Positive; // works
> // but:
> // alias Constrained!(int, (x) { return x > 0;}) Positive; // ka-boom!
> // alias Constrained!(int, x => x > 0) Positive; // no such luck

I ran into that problem also. I usually tend to define a function for
readability. It would be nice to have it working though, the last one is
definitely neat.

> enum OK = Positive(1); // OK
> enum NOK = Positive(-1); // Compiling error, cool!
> 
> So this works. That's nice to know, I never used an assert inside a CT
> evaluation.
> 
> Hmmm, validating XML and/or SQL queries at CT...

Yummy !


More information about the Digitalmars-d mailing list