Type inference and overloaded functions

Jonathan M Davis jmdavisProg at gmx.com
Mon Dec 9 22:52:40 PST 2013


On Tuesday, December 10, 2013 07:47:38 FreeSlave wrote:
> I just found weird D behavior about inference of array types.
> 
> Let's suppose we have these overloaded functions:
> 
> import std.stdio;
> 
> void bar(const(int[3]) arr)
> {
>      writeln("static array");
> }
> 
> void bar(const(int[]) arr)
> {
>      writeln("array slice");
> }
> 
> // In main we have something like that:
> int main(string[] args)
> {
>      bar([1,2,3]);
>      writeln(typeof([1,2,3]).stringof);
>      return 0;
> }
> 
> Weird thing is that the static array version of bar is called,
> but typeof().stringof is int[], not int[3].

Array literals are always dynamic arrays. int[3] is a static array.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list