[Issue 8026] New: Fix or disallow randomShuffle() on fixed-sized arrays
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu May 3 13:44:37 PDT 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8026
Summary: Fix or disallow randomShuffle() on fixed-sized arrays
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: enhancement
Priority: P2
Component: Phobos
AssignedTo: nobody at puremagic.com
ReportedBy: bearophile_hugs at eml.cc
--- Comment #0 from bearophile_hugs at eml.cc 2012-05-03 13:45:51 PDT ---
This comes after a report by Vidar Wahlberg:
http://forum.dlang.org/thread/jnu1an$rjr$1@digitalmars.com
Several functions of std.algorithm don't work with fixed-sized arrays, and
require you to slice them first to turn them into ranges. But
std.random.randomShuffle() accepts fixed-sized arrays as well:
import std.stdio: writeln;
import std.random: randomShuffle;
void main() {
int[6] data = [1, 2, 3, 4, 5, 6];
randomShuffle(data);
writeln(data);
}
This prints the unshuffled array:
[1, 2, 3, 4, 5, 6]
This is bug-prone, and in my opinion it's not acceptable.
I see two alternative solutions:
1) To make randomShuffle() properly support fixed-sized arrays, taking them by
reference;
2) To make randomShuffle() refuse a fixed-sized array at compile-time.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list