September 20, 2017 Re: static array with inferred size | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jonathan M Davis | On Wednesday, 20 September 2017 at 07:38:00 UTC, Jonathan M Davis wrote:
> T[n] s(T, size_t n)(auto ref T[n] array) pure nothrow @nogc @safe
> {
> return array;
> }
What about adding `s` to std.array in the meanwhile? I wonder what Walter says about the static array to slice assignment. Isn't it memory-safe?
|
September 20, 2017 Re: static array with inferred size | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nordlöw | On Wednesday, 20 September 2017 at 08:33:34 UTC, Nordlöw wrote:
> On Wednesday, 20 September 2017 at 07:38:00 UTC, Jonathan M Davis wrote:
>> T[n] s(T, size_t n)(auto ref T[n] array) pure nothrow @nogc @safe
>> {
>> return array;
>> }
>
> What about adding `s` to std.array in the meanwhile? I wonder what Walter says about the static array to slice assignment. Isn't it memory-safe?
Maybe even in object.d so that [1, 2, 3].s is possible without any import. Then it would look like a built-in feature.
|
September 20, 2017 Re: static array with inferred size | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dgame | On Wednesday, 20 September 2017 at 08:39:49 UTC, Dgame wrote:
> Maybe even in object.d so that [1, 2, 3].s is possible without any import. Then it would look like a built-in feature.
Good idea. Even better. I'll cook up a druntime-PR.
|
September 20, 2017 Re: static array with inferred size | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nordlöw | On Wednesday, September 20, 2017 08:33:34 Nordlöw via Digitalmars-d wrote: > On Wednesday, 20 September 2017 at 07:38:00 UTC, Jonathan M Davis > > wrote: > > T[n] s(T, size_t n)(auto ref T[n] array) pure nothrow @nogc > > @safe > > { > > > > return array; > > > > } > > What about adding `s` to std.array in the meanwhile? I wonder what Walter says about the static array to slice assignment. Isn't it memory-safe? If you use auto with the return value, you're fine, because you get a static array, and the orignal static array is copied, but if you assign it to a dynamic array, it's not at all memory safe. It's returning a slice of an rvalue and is a clear violation of https://issues.dlang.org/show_bug.cgi?id=12625 - Jonathan M Davis |
September 20, 2017 Re: static array with inferred size | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jonathan M Davis | 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. |
September 20, 2017 Re: static array with inferred size | ||||
---|---|---|---|---|
| ||||
Posted in reply to Per Nordlöw | 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.
- Jonathan M Davis
|
September 20, 2017 Re: static array with inferred size | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jonathan M Davis | 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
|
September 20, 2017 Re: static array with inferred size | ||||
---|---|---|---|---|
| ||||
Posted in reply to jmh530 | On 09/19/2017 11:05 PM, jmh530 wrote:
> On Wednesday, 20 September 2017 at 02:46:53 UTC, Meta wrote:
>>
>> [snip]
>
> I also favor making arr[..] equivalent to arr[0..$]
How would this be useful? -- Andrei
|
September 20, 2017 Re: static array with inferred size | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On Wednesday, 20 September 2017 at 12:10:47 UTC, Andrei Alexandrescu wrote:
>
> How would this be useful? -- Andrei
Really just an additional convenience, instead of writing slice[0..$, 0..$, 0..$, i], you would write slice[.., .., .., i].
|
September 20, 2017 Re: static array with inferred size | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | 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.
|
Copyright © 1999-2021 by the D Language Foundation