Understanding isInfinite(Range)

Pelle pelle.mansson at gmail.com
Mon Sep 6 09:47:45 PDT 2010


On 09/04/2010 02:11 PM, Simen kjaeraas wrote:
> Peter Alexander <peter.alexander.au at gmail.com> wrote:
>
>> == Quote from Steven Schveighoffer (schveiguy at yahoo.com)'s article
>>> On Fri, 03 Sep 2010 11:12:29 -0400, Andrej Mitrovic
>>> <andrej.mitrovich at 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 );
> }

enum s = "Hello";

assert (isStatic!s);

Gonna need more work than that.


More information about the Digitalmars-d-learn mailing list