On 2010-05-05 20:25:45 -0400, Walter Bright <newshou...@digitalmars.com> said:
bearophile wrote:
But the "specs" of the Range template say that Range must not work if
step is zero (this means that the unittest has to fail if Range
compiles when the given step is zero). So I have to test this too. I
can do that with one more unittest (D1 code):
static assert(!is(typeof( Range!(15, 3, 0) )));
In D2 I can use the __traits:
static assert(!__traits(compiles, Range!(15, 3, 0) ));
Oh, I see. You want to ensure it does not compile, rather than it
compiles. I got the ! flipped around.
If even Walter has difficulty figuring out the ! around __traits, I'll
take that as the ultimate proof that the current syntax has too much
cruft and is in need of a cleanup.
Could we at least replace this:
__traits(compiles, ...)
with this:
__traits.compiles(...)
It looks more readable to me at least, and it can be applied to other
traits. The next step would be to find a way to remove that ugly
__traits keyword, ideally without stealing a useful identifier. Perhaps
it should be made possible to do this:
module std.traits;
alias __traits.compiles compiles;
Now you just import std.traits and never write __traits again! :-)
static assert(!compiles( Range!(15, 3, 0) ));
--
Michel Fortin
michel.for...@michelf.com
http://michelf.com/