April 01, 2012
On Fri, 30 Mar 2012 19:52:50 +0200, simendsjo <simendsjo@gmail.com> wrote:

> On Fri, 30 Mar 2012 17:13:25 +0200, Simen Kjærås <simen.kjaras@gmail.com> wrote:
>>
>> Indeed. The thing is - U is basically *set* by the isExpression. It says
>> 'yes, there is such a U, so I'll add it to the local scope.'. This means
>> that U will be set for the entire scope within which the static if
>> exists.
>>
>> Due to the way the criteria are phrased, U is defined when the criteria
>> are not met, and as such are defined in the else clause instead of the
>> if clause.
>>
>>
>> { // Outer scope starts here.
>>    static if ( !is( const(int) t == const(U), U ) ) {
>>      // isExpression returned false, so U is undefined
>>    } else {
>>      // But here it is defined, because we're still in the same,
>>      // broader scope.
>>    }
>> }
>> // And here it's no longer defined.
>>
>> Was that any better? I admit I didn't understand it at first either, but
>> then I remembered that static if does not introduce a new scope. That
>> helped.
>
> I knew static if didn't create a new scope, but I still thought U would not be defined if it didn't match, but it seems it is defined just by existing in the scope.
> I had a bug when I tried to reproduce the behavior: I used typeof(U), which is, of course, not possible as U is a type :)
>
> Thanks for the explanation. Allowed to use D at work yet btw?

Not really. I use it a lot for scripts and fast prototyping, but it's
not the most flexible of organizations. Could use it for internal tools,
likely.
1 2
Next ›   Last »