Avoid subtracting form .length
monkyyy
crazymonkyyy at gmail.com
Sat Nov 9 01:09:56 UTC 2024
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
> this, no matter if a check is present or not.
> What's the recommended fix for this? I have no idea what else
> to use.
write a utility function? ~~after turning off dscanner~~
More information about the Digitalmars-d-learn
mailing list