One case of array assignments
Chris Nicholson-Sauls
ibisbasenji at gmail.com
Mon Mar 18 14:35:41 PDT 2013
On Thursday, 14 March 2013 at 01:34:02 UTC, Marco Leise wrote:
> Am Wed, 13 Mar 2013 14:31:42 -0700
> schrieb "H. S. Teoh" <hsteoh at quickfur.ath.cx>:
>
>> Why is it bad to have to explicitly list the elements for
>> static
>> initialization?
>
> Because of:
>
> struct CompressionData
> {
> ubyte[4096] x =
> [0,0,0 /* ...ad nauseum... */ ,0,0];
> }
struct CompressionData
{
ubyte[4096] x; // note this is already [0...0] thanks
// to default init... but still:
this ()
{
x[] = 0;
}
}
--- Or even: ---
import std.range;
struct CompressionData
{
ubyte[4096] x = repeat( 0 )[ 0 .. 4096 ];
}
Assuming repeat()[] is CTFE-able (didn't test).
More information about the Digitalmars-d
mailing list