filling arrays, avoid default init

Lionello Lunesu lionello at lunesu.remove.com
Tue Jan 9 22:51:09 PST 2007


>> Uhm, sorry. That doesn't seem to prevent the initialization at all...
>
> Can you provide a code sampel?

Well, Frank's code:

TypeA[] ta = .... ; // big array with something
TypeB[] tb = void;
tb.length = ta.length; // (1)
foreach( uint i, TypeA a; ta ){
  tb[i] = ta[i].getB();
}

For unsized dynamic arrays (TypeB[]), =void does not prevent the 
initialization when you change the length later.

L. 




More information about the Digitalmars-d-learn mailing list