Request: a more logical static array behavior
Tommi
tommitissari at hotmail.com
Thu Aug 15 07:32:28 PDT 2013
On Thursday, 15 August 2013 at 13:50:45 UTC, Maxim Fomin wrote:
> On Thursday, 15 August 2013 at 12:44:09 UTC, Tommi wrote:
>>
>> I don't expect int[3] to implicitly convert to int[] during
>> type deduction for the same reason that I don't expect int to
>> implicitly convert to long during type deduction (even though
>> I know that int implicitly converts to long in all kinds of
>> other contexts):
>>
>> void getLong(T)(T arg)
>> if (is(T == long))
>> {
>> }
>>
>> void main()
>> {
>> int n;
>> getLong(n); // int doesn't implicitly convert to long
>> }
>>
>
> OK,
>
> void getLong(T)(T arg)
> if (is(T : long))
> {
>
> }
>
> void main()
> {
> int n;
> getLong(n); // int is implicitly convertible to long
> }
>
> now you have "implicit conversion from int to long during type
> deduction".
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
}
More information about the Digitalmars-d
mailing list