initializing a static array
Daniel Kozak
kozzi11 at gmail.com
Tue Oct 10 13:54:16 UTC 2017
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" <digitalmars-d-learn at puremagic.com>:
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
double[n] bar = 0; // does not compile
double[n] bar = {0}; // neither does this
double[n] bar = [0]; // compiles, but only sets the first element,
ignoring the rest
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
might be missing something obvious here...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20171010/3296ee14/attachment.html>
More information about the Digitalmars-d-learn
mailing list