One case of array assignments

Craig Dillabaugh cdillaba at cg.scs.carleton.ca
Tue Mar 19 08:27:39 PDT 2013


On Monday, 18 March 2013 at 21:35:43 UTC, Chris Nicholson-Sauls
wrote:
clip
>
> 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).

You could also uses mixin's to build these long static arrays. I
think there is a good example in Andrei's book.


More information about the Digitalmars-d mailing list