Type inference and overloaded functions
Namespace
rswhite4 at googlemail.com
Wed Dec 11 12:09:54 PST 2013
On Wednesday, 11 December 2013 at 19:51:24 UTC, bearophile wrote:
> Namespace:
>
>> void main() {
>> int[] arr0 = [1, 2, 3];
>> assert(is(typeof(arr0) == int[]));
>> assert(arr0 == [1, 2, 3]);
>>
>> int[3] arr1 = [4, 5, 6]s;
>> assert(is(typeof(arr1) == int[3]));
>> assert(arr1 == [4, 5, 6]);
>>
>> int[] arr2 = [7, 8, 9]s;
>> assert(is(typeof(arr2) == int[/*3*/]));
>> assert(arr2 == [7, 8, 9]);
>>
>> int[$] arr_a1 = [54, 74, 90, 2010];
>> assert(is(typeof(arr_a1) == int[4]));
>> assert(arr_a1 == [54, 74, 90, 2010]);
>>
>> int[$] arr_a2 = [2010, 90, 74, 54]s;
>> assert(is(typeof(arr_a2) == int[4]));
>> assert(arr_a2 == [2010, 90, 74, 54]);
>>
>> foo([1, 2, 3]);
>> foo([4, 5, 6]s);
>>
>> bar([44, 55, 66]s);
>>
>> auto arr3 = [111, 222, 333];
>> assert(is(typeof(arr3) == int[]));
>>
>> auto arr4 = [444, 555, 666]s;
>> assert(is(typeof(arr4) == int[3]));
>>
>> quatz([3, 2, 1]);
>> quatz([8, 7, 6]s);
>> }
>
> Very good, this seems a step forward for D. Are you going to
> create two pull requests for dmd? (it will not be accepted
> before dmd 2.066).
I'm unsure. I'm not that familiar with dmd at all, so maybe some
more advanced guy like Kenji should review my code and create an
own, better pull. What do you mean?
>
> Is it also guarding against this?
> http://d.puremagic.com/issues/show_bug.cgi?id=3849
>
> That in short is this mistake (this currently doesn't give
> errors):
>
> string[3] a = ["red""green","blue"];
> void main() {}
>
> Bye,
> bearophile
Not yet tested, but I will. :)
More information about the Digitalmars-d-learn
mailing list