On Thursday, 14 November 2024 at 13:08:36 UTC, Manfred Nowak
wrote:
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:
On Thursday, 14 November 2024 at 13:24:47 UTC, Dom DiSc wrote:
No, no. My problem is: [...]
So it seems, that the intended problem was transposed into
some example, thereby oblittering that problem with some
coding errors.
I checked that the source array has at least one element.
Yes, but on
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
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;
}
```
I consider this perfectly safe, but DScanner gives warnings for
On Friday, November 8, 2024 4:27:40 PM MST Dom DiSc via Digitalmars-d-learn
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 thi
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 use `a.length +(-1)`. It's not pretty but at least dscanner i
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
12 matches
Mail list logo