Type inference and overloaded functions

Marco Leise Marco.Leise at gmx.de
Tue Dec 10 13:34:54 PST 2013


Am Tue, 10 Dec 2013 11:56:40 +0100
schrieb "Kenji Hara" <k.hara.pg at gmail.com>:

> On Tuesday, 10 December 2013 at 07:32:08 UTC, Marco Leise wrote:
> > [1,2,3] looks like a static array to me. And if overload
> > resolution picked the most specialized function it seems
> > natural to call the int[3] version.
> > My reasoning being that static arrays can be implicitly
> > converted to dynamic array, but the reverse is not true. So I
> > think it would be better to have [1,2,3] be a static array and
> > keep the current behavoir, no?)
> 
> In early D1 age, array literals and string literals had had 
> static array types which corresponding to the literals' element 
> count. However it had caused template code bloat.
> 
> void foo(T)(T arg) { ... }
> 
> foo("aaa");   // instantiate foo!(char[3])
> foo("bbbb");  // instantiate foo!(char[4])
> 
> foo([1,2]);    // instantiate foo!(int[2])
> foo([1,2,3]);  // instantiate foo!(int[3])
> 
> So their types were changed to dynamic array by default.
> 
> Kenji Hara

I understand that. The string case probably being the most
heavy weight one that prompted the change. Damn, compilers are
complicated.

-- 
Marco



More information about the Digitalmars-d-learn mailing list