Re: Is this a correct way to make this code working at compile time?

2024-11-18 Thread Dom DiSc via Digitalmars-d-learn
On Monday, 18 November 2024 at 21:59:43 UTC, Andrey Zherikov wrote: Is this a correct/safe way to go since I'm copying `const string[]` to `string[]`? Copying constants to variables is something absolutely normal. If this wouldn't work, how would you program at all? So, yes this is safe and c

Is there a way to make a struct without a distinction between constant, immutable, and mutable?

2024-11-18 Thread Liam McGillivray via Digitalmars-d-learn
I am doing work on the `units-d` library. This library contains some struct templates which don't contain any variables. Because of this, all instances are effectively constant. However, when they are placed as arguments in other templates, it causes problems when one is unexpectedly `const`.

Is this a correct way to make this code working at compile time?

2024-11-18 Thread Andrey Zherikov via Digitalmars-d-learn
Below is the reduced code that replicates my problem. I'm trying to remember a value (of some type) that can be used at run time (assigned to a variable). "Remembering" must be done at compile time because it's a part of UDA. ```d // I can't get rid of this struct because it contains a lot of

Re: Avoid subtracting form .length

2024-11-18 Thread Paolo Invernizzi via Digitalmars-d-learn
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: