Discussion Thread: DIP 1039--Static Arrays with Inferred Length--Community Review Round 1

Dukc ajieskola at gmail.com
Wed Jan 6 18:58:38 UTC 2021


On Wednesday, 6 January 2021 at 18:41:31 UTC, Nick Treleaven 
wrote:
> On Wednesday, 6 January 2021 at 18:33:54 UTC, Dukc wrote:
>> Why? `arr` is static so the compiler should be able to figure 
>> that no overflow will ever happen.
>
> Because:
> 1. concatenation with a static array is not defined (use 
> `arr[]`).

Oh okay.

> 2. slices do not implicitly convert to a static array.

They do if the length is known at compile time, but `~` does not 
for some reason propagate the length. This works though:

```
int[4] bar(int[2] arr)
{   return arr.conc([3, 4]);
}

T[i+j] conc(T, size_t i, size_t j)(T[i] a, T[j] b)
{	typeof(return) result;
	result[0 .. i] = a[];
	result[i .. $] = b[];
	return result;
}
```



More information about the Digitalmars-d-announce mailing list