Fixed-size arrays and randomShuffle()

Vidar Wahlberg canidae at exent.net
Thu May 3 06:30:49 PDT 2012


May be that this works as intended, but it fooled me:
---
import std.random;
import std.stdio;
void main() {
         int[5] a = 0;
         a[0] = 1;
         int[] b = [1, 0, 0, 0, 0];
         randomShuffle(a);
         writeln(a);
         randomShuffle(b);
         writeln(b);
}
---

In DMD 2.0.59 the fixed-size array "a" won't be shuffled (the dynamic 
array "b" will), and you won't get any warning about it.

I'm not sure whether this counts as something that should be reported as 
a bug/improvement, nor if only randomShuffle() displays this behaviour, 
perhaps you could enlighten me.


More information about the Digitalmars-d-learn mailing list