Re: How can we view source code that has been generated (say via "static foreach") ?

2021-09-15 Thread james.p.leblanc via Digitalmars-d-learn
On Thursday, 16 September 2021 at 03:26:46 UTC, Tejas wrote: On Wednesday, 15 September 2021 at 19:59:43 UTC, james.p.leblanc wrote: s Use the `mixin` compiler flag `dmd -mixin= file.d` Beware, this will also include **all** the mixin code from standard library and runtime. But it's

Re: How can we view source code that has been generated (say via "static foreach") ?

2021-09-15 Thread Tejas via Digitalmars-d-learn
On Wednesday, 15 September 2021 at 19:59:43 UTC, james.p.leblanc wrote: Dear All, In attempting to learn and use code generation, it would be useful to be able to view the source code that gets generated. However, with various combinations of templates, UDAs, and mixins it has not been easy.

Re: Program crash: GC destroys an object unexpectedly

2021-09-15 Thread jfondren via Digitalmars-d-learn
On Tuesday, 14 September 2021 at 20:59:14 UTC, Ali Çehreli wrote: On 9/14/21 9:56 AM, eugene wrote: > On Tuesday, 14 September 2021 at 16:43:50 UTC, jfondren wrote: >> The misaligned pointer and the >> reference-containing struct that vanishes on the return of your >> corresponding function

Re: Return complete multi-dimensional array after appending

2021-09-15 Thread eXodiquas via Digitalmars-d-learn
On Wednesday, 15 September 2021 at 21:02:29 UTC, Paul Backus wrote: On Wednesday, 15 September 2021 at 20:32:12 UTC, eXodiquas wrote: ```d [1,0,3,4,0,5] .fold!((a, e) => e != 0 ? a[0] ~ e : a[1] ~ e)(cast(int[][]) [[],[]]) .flatten .writeln ``` This should sort all non 0s into the `a[0]`

Re: Return complete multi-dimensional array after appending

2021-09-15 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 15 September 2021 at 20:32:12 UTC, eXodiquas wrote: ```d [1,0,3,4,0,5] .fold!((a, e) => e != 0 ? a[0] ~ e : a[1] ~ e)(cast(int[][]) [[],[]]) .flatten .writeln ``` This should sort all non 0s into the `a[0]` array and all 0s into the `a[1]` array. But it won't work because the

Return complete multi-dimensional array after appending

2021-09-15 Thread eXodiquas via Digitalmars-d-learn
Howdy everyone. :) Today I came across a small problem (I mean, I could solve it by writing a function that solves my problem, but maybe there is something in std that can help me here). Let's say we have the following code: ```d void main() { int[][] a = [[],[]]; (a[0] ~ 5).writeln; //

How can we view source code that has been generated (say via "static foreach") ?

2021-09-15 Thread james.p.leblanc via Digitalmars-d-learn
Dear All, In attempting to learn and use code generation, it would be useful to be able to view the source code that gets generated. However, with various combinations of templates, UDAs, and mixins it has not been easy. Is there some standard way this is done? Optimal would be to print out

Re: Was this supposed to be allowed?

2021-09-15 Thread Petar via Digitalmars-d-learn
On Wednesday, 15 September 2021 at 13:52:40 UTC, z wrote: ```D float[2] somevalue = somefloat3value[] + cast(Unqual!float[2]) [somesharedfloatarray1[i],somesharedfloatarray2[ii]]; ``` Older LDC/DMD releases never complained but now that i upgraded DMD, DMD-compiled builds suffer from runtime

Re: uint overflow behaviour

2021-09-15 Thread DLearner via Digitalmars-d-learn
Thanks for the responses.

Was this supposed to be allowed?

2021-09-15 Thread z via Digitalmars-d-learn
```D float[2] somevalue = somefloat3value[] + cast(Unqual!float[2]) [somesharedfloatarray1[i],somesharedfloatarray2[ii]]; ``` Older LDC/DMD releases never complained but now that i upgraded DMD, DMD-compiled builds suffer from runtime assert error

Re: uint overflow behaviour

2021-09-15 Thread Steven Schveighoffer via Digitalmars-d-learn
On Wednesday, 15 September 2021 at 10:08:13 UTC, DLearner wrote: Please confirm that if the addition of two uint variables produces a result larger than can be held in a uint: 1. This is a D-legal operation (however inadvisable!), with the D-defined result of wraparound; Definition under

Re: uint overflow behaviour

2021-09-15 Thread rikki cattermole via Digitalmars-d-learn
https://dlang.org/spec/expression.html#add_expressions "7. If both operands are of integral types and an overflow or underflow occurs in the computation, wrapping will happen. For example, uint.max + 1 == uint.min, uint.min - 1 == uint.max, int.max + 1 == int.min, and int.min - 1 == int.max."

uint overflow behaviour

2021-09-15 Thread DLearner via Digitalmars-d-learn
Please confirm that if the addition of two uint variables produces a result larger than can be held in a uint: 1. This is a D-legal operation (however inadvisable!), with the D-defined result of wraparound; 2. Emphasing 1. above: the result is not undefined, or an error (by the rules of D),