Re: Avoid subtracting form .length

2024-11-08 Thread Jonathan M Davis via Digitalmars-d-learn
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

Re: Avoid subtracting form .length

2024-11-08 Thread Anonymouse via Digitalmars-d-learn
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

Re: Avoid subtracting form .length

2024-11-08 Thread monkyyy via Digitalmars-d-learn
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

Avoid subtracting form .length

2024-11-08 Thread Dom DiSc via Digitalmars-d-learn
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 rec

Re: Why doesn't `opAssign` work for my templated struct?

2024-11-08 Thread monkyyy via Digitalmars-d-learn
On Friday, 8 November 2024 at 21:55:53 UTC, Liam McGillivray wrote: if(isNumeric!T) ``` Error: cannot implicitly convert expression `40.0F` of type `float` to `Milligrams` ``` I dont believe phoboes type detection templates are well designed; given some sort of type pattern matching issue yo

Why doesn't `opAssign` work for my templated struct?

2024-11-08 Thread Liam McGillivray via Digitalmars-d-learn
I am working on a library for making types representing units of measurement. Base units are derived from a struct called `BaseUnit`. I want to make it so that `BaseUnit`-derived types can have their values assigned from float constants, but not from each-other or from float variables. I just

Re: Error with -betterC

2024-11-08 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
On 09/11/2024 4:03 AM, Maximilian Naderer wrote: On Friday, 8 November 2024 at 11:21:33 UTC, Richard (Rikki) Andrew Cattermole wrote: On 09/11/2024 12:10 AM, Maximilian Naderer wrote: Is the -betterC config not creating the equals, hash functions which are generated by D ? I just checked, no.

Re: Error with -betterC

2024-11-08 Thread Maximilian Naderer via Digitalmars-d-learn
On Friday, 8 November 2024 at 11:21:33 UTC, Richard (Rikki) Andrew Cattermole wrote: On 09/11/2024 12:10 AM, Maximilian Naderer wrote: Is the -betterC config not creating the equals, hash functions which are generated by D ? I just checked, no. Hello Rikki, Thanks for checking. Just to conf

Re: Error with -betterC

2024-11-08 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
On 09/11/2024 12:10 AM, Maximilian Naderer wrote: Is the -betterC config not creating the equals, hash functions which are generated by D ? I just checked, no.

Error with -betterC

2024-11-08 Thread Maximilian Naderer via Digitalmars-d-learn
I have the following struct with i compile with -betterC into a static library. ```d struct SubmitDesc { union { uint[4] viewport; struct { uint vpx; uint vpy; uint vpw; uint vph; } } union { float[4] c