Why is (int[int] s = int[int].init) not allowed

Daniel Kozak kozzi11 at gmail.com
Wed Dec 23 07:08:31 UTC 2020


Dne st 23. 12. 2020 1:00 uživatel Steven Schveighoffer via
Digitalmars-d-learn <digitalmars-d-learn at puremagic.com> napsal:

> On 12/22/20 5:44 PM, Daniel Kozak wrote:
> > On Tue, Dec 22, 2020 at 10:15 PM Andre Pany via Digitalmars-d-learn
> > <digitalmars-d-learn at puremagic.com
> > <mailto:digitalmars-d-learn at puremagic.com>> wrote:
> >
> >     Hi,
> >
> >     I am really confused, why is this valid:
> >     void sample(string[string] s = string[string].init){}
> >
> >     while this causes syntax errors?
> >
> >     void sample_invalid1(double[string] s = double[string].init){}
> >     void sample_invalid2(int[int] s = int[int].init){}
> >
> >     Kind regards
> >     André
> >
> >
> > As has been said this is an oddity in the grammar. But why would anyone
> > need to use this anyway?
> >
> >    void sample_invalid2(int[int] s = int[int].init){}
> >
> > seems really awful to me anyway.
>
> Yeah:
>
> void sample_valid(int[int] s = null)
>
> -Steve


Yes AA.init is null per doc.

https://dlang.org/spec/hash-map.html#construction_and_ref_semantic
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20201223/8fad7208/attachment.htm>


More information about the Digitalmars-d-learn mailing list