[Issue 18631] New: std.random.choice does not work with const arrays
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Mar 19 19:30:39 UTC 2018
https://issues.dlang.org/show_bug.cgi?id=18631
Issue ID: 18631
Summary: std.random.choice does not work with const arrays
Product: D
Version: D2
Hardware: x86
OS: Windows
Status: NEW
Severity: enhancement
Priority: P1
Component: phobos
Assignee: nobody at puremagic.com
Reporter: elpenguino+D at gmail.com
```
const x = [1,2];
auto y = choice(x);
```
results in
```
/dlang/dmd/linux/bin64/../../src/phobos/std/random.d(2033): Error: template
std.random.choice cannot deduce function from argument types !()(const(int[]),
MersenneTwisterEngine!(uint, 32LU, 624LU, 397LU, 31LU, 2567483615u, 11LU,
4294967295u, 7LU, 2636928640u, 15LU, 4022730752u, 18LU, 1812433253u)),
candidates are:
/dlang/dmd/linux/bin64/../../src/phobos/std/random.d(2020):
std.random.choice(Range, RandomGen = Random)(auto ref Range range, ref
RandomGen urng) if (isRandomAccessRange!Range && hasLength!Range &&
isUniformRNG!RandomGen)
/dlang/dmd/linux/bin64/../../src/phobos/std/random.d(2031):
std.random.choice(Range)(auto ref Range range)
onlineapp.d(5): Error: template instance `std.random.choice!(const(int[]))`
error instantiating
```
It appears that the only thing keeping this from working is x not being a
range, but the body of the function does not seem to actually require that be
true.
--
More information about the Digitalmars-d-bugs
mailing list