Type inference and overloaded functions
Ali Çehreli
acehreli at yahoo.com
Thu Dec 12 07:21:49 PST 2013
On 12/11/2013 05:09 PM, bearophile wrote:
> Ali Çehreli:
>
>> > int[] arr2 = [7, 8, 9]s;
>> > assert(is(typeof(arr2) == int[3]));
>>
>> That looks very confusing. The left-hand side looks like a slice,
>> which I can append elements to but its type is a static array?
>
> No, the type of the literal is of a fixed-side array, but it gets
> assigned to a dynamic array, so it's a slice.
No problem there.
> I am not sure but I Think
> arr2 data is allocated on the stack.
Although important, I wasn't considering that point at all.
> It looks a little confusing, but I
> think it contains a rule we can learn.
But look at the assertion: the type of the *slice* arr2 is int[3]. :)
>
> Bye,
> bearophile
>
Ali
More information about the Digitalmars-d-learn
mailing list