static array with inferred size

Jonathan M Davis newsgroup.d at jmdavisprog.com
Wed Sep 20 13:45:57 UTC 2017


On Wednesday, September 20, 2017 12:59:02 Meta via Digitalmars-d wrote:
> On Wednesday, 20 September 2017 at 12:41:57 UTC, Stefan Koch
>
> wrote:
> > On Wednesday, 20 September 2017 at 12:08:45 UTC, Andrei
> >
> > Alexandrescu wrote:
> >> On 09/20/2017 07:49 AM, Jonathan M Davis wrote:
> >>> On Wednesday, September 20, 2017 10:59:56 Per Nordlöw via
> >>> Digitalmars-d
> >>>
> >>> wrote:
> >>>> On Wednesday, 20 September 2017 at 09:13:52 UTC, Jonathan M
> >>>> Davis
> >>>>
> >>>> wrote:
> >>>>> https://issues.dlang.org/show_bug.cgi?id=12625
> >>>>>
> >>>>> - Jonathan M Davis
> >>>>
> >>>> Looks like we should we wait for
> >>>> https://github.com/dlang/dmd/pull/7110 to be merged before
> >>>> adding
> >>>> `s` to druntime.
> >>>
> >>> It also should have a much more descriptive name (e.g.
> >>> staticArray, though
> >>> maybe that's a bit long), and I think that std.array really
> >>> does make more
> >>> sense than object.d. object.d is for stuff that's essentially
> >>> built-in, not
> >>> for helper functions.
> >>
> >> Agreed. Also: the length of the name should not be a problem,
> >> this is not a frequently used facility. -- Andrei
> >
> > I do strongly disagree with this approach, rather we should
> > type array literals as static arrays by default and rely on
> > implicit conversion to slices.
>
> A long time ago I believe this was the case, but it was changed
> because it caused a lot of problems. What they were I don't know.

The simple fact that static arrays implicitly convert to dynamic arrays
causes all kinds of problems. DIP 1000 should improve that situation (at
least as far as memory safety goes), but in general, I'm convinced that
having that implicit conversion was a serious mistake.

And as for specific problems with typing array literals as static arrays,
the first thing that comes to mind is that it won't work with range-based
functions, whereas as long as they're dynamic arrays, it will.

- Jonathan M Davis




More information about the Digitalmars-d mailing list