On Thursday, 14 November 2024 at 17:27:54 UTC, user1234 wrote:
You define a contract that Dscanner does not understand. The
more simple solution, as you seem to be careful about bounds,
is to disable the specific check that worries you.
Ok. Somewhat sad, but at least it works.
Thanks for all t
On Friday, 8 November 2024 at 23:27:40 UTC, Dom DiSc wrote:
I _very_ often use this pattern:
```
fun(ref int[] a)
{
assert(a.length && a.length<=100);
int[100] b;
b[0 .. a.length-1] = a[];
b[a.length .. 100] = 5;
}
```
I consider this perfectly safe, but DScanner gives warnings for
On Thursday, 14 November 2024 at 06:53:01 UTC, Salih Dincer wrote:
On Friday, 8 November 2024 at 23:27:40 UTC, Dom DiSc wrote:
I _very_ often use this pattern:
```d
fun(ref int[] a)
{
assert(a.length && a.length<=100);
int[100] b;
b[0 .. a.length-1] = a[];
b[a.length .. 100] = 5;
}
No, no. My problem is: I want to access the last element of an
array and assign it to the element of same index in another array
(so I can't use $), and I checked that the source array has at
least one element.
The questions are:
- Why is it considered dangerous to use the expression a.length-
On Saturday, 9 November 2024 at 04:02:46 UTC, Jonathan M Davis
wrote:
[...]
b[0 .. a.length-1] = a[];
You'll get a RangeError being thrown when you run the code.
[...]
Therefore a fix might be to not deminish the length:
b[ 0 .. a.length]= a[];
-manfred
On Friday, 8 November 2024 at 23:27:40 UTC, Dom DiSc wrote:
...
My version:
import std.stdio, std.array, std.range, std.algorithm;
void foo(ref int[] a, int filler){
int[5] b;
auto len = min(b.length,a.length);
b[0..len] = a[0..len];
b[len..5] = filler;
writeln("a = ", a);
w