Send empty assoc array to function

Max Samukha maxsamukha at gmail.com
Fri Jul 10 08:15:24 UTC 2020


On Thursday, 9 July 2020 at 21:04:57 UTC, Steven Schveighoffer 
wrote:

>> 
>> Why isn't [] accepted as an empty AA literal?
>
> Because it's an empty dynamic array literal.
>
> If D were to accept an empty AA literal, I'd expect it to be 
> [:].
>
> -Steve

Just as typeof(null) is a subtype of all nullable types, you 
could make typeof([]) a subtype of both AAs and dynamic arrays. 
[:] could still be made a specifically AA literal.

BTW, writeln((int[int]).init) prints "[]" (to!string((V[K]).init) 
== "[]"), but pragma(msg, (int[int]).init) - the more general 
'null' ((V[K]).init.stringof == "null"), which is a unfortunate 
inconsistency.


More information about the Digitalmars-d-learn mailing list