Type inference and overloaded functions

Namespace rswhite4 at googlemail.com
Tue Dec 10 12:07:18 PST 2013


On Tuesday, 10 December 2013 at 14:20:51 UTC, bearophile wrote:
> Namespace:
>
>> What's with {1, 2, 3}? Should be easy to implement and it's 
>> known from C/C++/Java/C#
>
> In D {} has plenty of meanings already :-)
>
> Bye,
> bearophile

I've tried it in the last hour and as I thought, with a few 
changes it is very easy to implement (it needs currently ~30 
lines - however my knowledge of the compiler is very limited, so 
that it could need some more changes).

But a short test shows, that something like this is possible with 
my changes:

----
int[] arr0 = [1, 2, 3];
assert(is(typeof(arr0) == int[]));
assert(arr0 == [1, 2, 3]);

int[3] arr1 = {1, 2, 3};
assert(is(typeof(arr1) == int[3]));
assert(arr1 == [1, 2, 3]);

int[] arr2 = {4, 5, 6};
assert(is(typeof(arr2) == int[3]));
assert(arr2 == [4, 5, 6]);
----

I like it. :D


More information about the Digitalmars-d-learn mailing list