Type inference and overloaded functions

Chris Cain clcain at uncg.edu
Wed Dec 11 08:28:38 PST 2013


On Wednesday, 11 December 2013 at 09:49:13 UTC, Namespace wrote:
> On Wednesday, 11 December 2013 at 04:01:11 UTC, Ali Çehreli 
> wrote:
>> On 12/10/2013 04:37 PM, Namespace wrote:
>>
>> >     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?
>>
>> Ali
>
> That is intended (but can be discussed of course). It was often 
> desired to write int[$] arr = [1, 2, 3]; to auto-determine the 
> dimension. And my change does something like that: if you 
> assign a static array to a slice, the dimension is 
> auto-determined and the type is adapted.

I agree with Ali. arr2 says it's a dynamic array but it's not. 
This could easily lead to errors worse than the class caused by 
implicit conversions (what's worse than explicitly saying you 
want an x but getting a y instead?). `int[$]` for this purpose 
would be acceptable, however. I actually like that idea, 
personally.


More information about the Digitalmars-d-learn mailing list