www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 18631] New: std.random.choice does not work with const arrays


          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 puremagic.com
          Reporter: elpenguino+D 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:
std.random.choice(Range, RandomGen = Random)(auto ref Range range, ref
RandomGen urng) if (isRandomAccessRange!Range && hasLength!Range &&
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

Mar 19 2018