Re: initializing a static array

2017-10-10 Thread kinke via Digitalmars-d-learn
On Tuesday, 10 October 2017 at 22:00:27 UTC, kinke wrote: [...] Ah sorry, overlooked that it's the initializer for a struct field.

Re: initializing a static array

2017-10-10 Thread kinke via Digitalmars-d-learn
On Tuesday, 10 October 2017 at 14:15:07 UTC, Simon Bürger wrote: On Tuesday, 10 October 2017 at 13:48:16 UTC, Andrea Fontana wrote: Maybe: double[n] bar = 0.repeat(n).array; This works fine, thanks a lot. I would have expected `.array` to return a dynamic array. But apparently the compiler

Re: initializing a static array

2017-10-10 Thread ag0aep6g via Digitalmars-d-learn
On 10/10/2017 03:36 PM, Simon Bürger wrote: I have a static array inside a struct which I would like to be initialized to all-zero like so   struct Foo(size_t n)   {     double[n] bar = ... all zeroes ...   } (note that the default-initializer of double is nan, and not zero) I tried  

Re: initializing a static array

2017-10-10 Thread Daniel Kozak via Digitalmars-d-learn
https://run.dlang.io/is/SC3Fks

Re: initializing a static array

2017-10-10 Thread Daniel Kozak via Digitalmars-d-learn
Yeah, you are right. My fault. On Tue, Oct 10, 2017 at 4:47 PM, Adam D. Ruppe via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > On Tuesday, 10 October 2017 at 14:42:15 UTC, Daniel Kozak wrote: > >> It will return dynamic array. it is same as: >> >> double[5] = [0,0,0,0,0]; //

Re: initializing a static array

2017-10-10 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 10 October 2017 at 14:42:15 UTC, Daniel Kozak wrote: It will return dynamic array. it is same as: double[5] = [0,0,0,0,0]; // this is still dynamicaly allocated. Not true here, the compiler knows it is going into a static array and puts the result directly in there. It handles

Re: initializing a static array

2017-10-10 Thread Daniel Kozak via Digitalmars-d-learn
On Tue, Oct 10, 2017 at 4:15 PM, Simon Bürger via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > On Tuesday, 10 October 2017 at 13:48:16 UTC, Andrea Fontana wrote: > >> On Tuesday, 10 October 2017 at 13:36:56 UTC, Simon Bürger wrote: >> >>> Is there a good way to set them all

Re: initializing a static array

2017-10-10 Thread Simon Bürger via Digitalmars-d-learn
On Tuesday, 10 October 2017 at 13:54:16 UTC, Daniel Kozak wrote: struct Double { double v = 0; alias v this; } struct Foo(size_t n) { Double[n] bar; } Interesting approach. But this might introduce problems later. For example `Double` is implicitly convertible to `double`, but

Re: initializing a static array

2017-10-10 Thread Simon Bürger via Digitalmars-d-learn
On Tuesday, 10 October 2017 at 13:48:16 UTC, Andrea Fontana wrote: On Tuesday, 10 October 2017 at 13:36:56 UTC, Simon Bürger wrote: Is there a good way to set them all to zero? The only way I can think of is using string-mixins to generate a string such as "[0,0,0,0]" with exactly n zeroes.

Re: initializing a static array

2017-10-10 Thread Andrea Fontana via Digitalmars-d-learn
On Tuesday, 10 October 2017 at 13:53:37 UTC, jmh530 wrote: double[n] bar; bar[] = 0; This works at runtime only for mutable arrays, anyway.

Re: initializing a static array

2017-10-10 Thread jmh530 via Digitalmars-d-learn
On Tuesday, 10 October 2017 at 13:48:16 UTC, Andrea Fontana wrote: Maybe: double[n] bar = 0.repeat(n).array; Alt: double[n] bar; bar[] = 0;

Re: initializing a static array

2017-10-10 Thread Daniel Kozak via Digitalmars-d-learn
struct Double { double v = 0; alias v this; } struct Foo(size_t n) { Double[n] bar; } Dne 10. 10. 2017 3:40 odpoledne napsal uživatel "Simon Bürger via Digitalmars-d-learn" : I have a static array inside a struct which I would like to be

Re: initializing a static array

2017-10-10 Thread Andrea Fontana via Digitalmars-d-learn
On Tuesday, 10 October 2017 at 13:36:56 UTC, Simon Bürger wrote: Is there a good way to set them all to zero? The only way I can think of is using string-mixins to generate a string such as "[0,0,0,0]" with exactly n zeroes. But that seems quite an overkill for such a basic task. I suspect I