Peter Alexander <peter.alexander...@gmail.com> wrote:
== Quote from Steven Schveighoffer (schvei...@yahoo.com)'s article
On Fri, 03 Sep 2010 11:12:29 -0400, Andrej Mitrovic
<andrej.mitrov...@test.com> wrote:
> What does char[1 + Range.empty] do? It looks rather cryptic..
char[1+Range.empty] is a type. If Range.empty is a compile-time
constant,
then this type is valid, otherwise it's not valid (the is expression
results to true if the argument is a valid type).
If it's valid, then Range.empty never changes. If it never changes and
it's always false, then it's infinite.
-Steve
That's really ugly code :-(
Is there a way you could write an isStatic(expr) template? Using
something like that would make the
code a hell of a lot more readable. At the moment, the code itself does
a very poor job of conveying
what it's trying to accomplish.
These SFINAE-like tricks should be black-boxed as much as possible, or
(at the very least)
commented so that people know what's going on.
template isStatic( alias T ) {
enum isStatic = is( char[1+T] );
}
unittest {
int n = 3;
assert( !isStatic!n );
assert( isStatic!1 );
enum r = 5;
assert( isStatic!r );
}
--
Simen