Request: a more logical static array behavior

Tommi tommitissari at hotmail.com
Thu Aug 15 08:07:21 PDT 2013


On Thursday, 15 August 2013 at 14:53:08 UTC, Maxim Fomin wrote:
> On Thursday, 15 August 2013 at 14:32:29 UTC, Tommi wrote:
>>
>> No it's not:
>>
>> void getLong(T)(T arg)
>> if (is(T : long))
>> {
>>    static assert(is(typeof(arg) == int));
>> }
>>
>> void main()
>> {
>>    int n;
>>    getLong(n); // int is _not_ implicitly converted to long
>> }
>
> Yes, because during type deduction there was constraint test 
> that checked whether int is convertible to long which is the 
> same story as in static-dynamic array case.

The code snippet above is not the same thing as what happens in 
the static-dynamic array case. In the above code snippet the type 
deduction for 'T' during the instantiation of 'getLong' has 
already finished by the time the template constraint is evaluated 
(how could the template constraint be evaluated if the actual 
type for 'T' hadn't already been deduced?). So, the compiler 
doesn't consider the implicit conversion from int to long 
_during_ type deduction, but after it.

The only time when the compiler is willing to consider the 
possible implicit conversions during type deduction is with 
static arrays: hence... "magic".


More information about the Digitalmars-d mailing list