Skip to content

Commit

Permalink
fix issue 18631 - Allow choice to work with const arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
Lars-Kristiansen committed Mar 19, 2018
1 parent 13d0490 commit 4031411
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion std/random.d
Original file line number Diff line number Diff line change
Expand Up @@ -2017,7 +2017,7 @@ Returns:
return a `ref` to the $(D range element), otherwise it will return
a copy.
*/
auto ref choice(Range, RandomGen = Random)(auto ref Range range,
auto ref choice(Range, RandomGen = Random)(inout auto ref Range range,
ref RandomGen urng)
if (isRandomAccessRange!Range && hasLength!Range && isUniformRNG!RandomGen)
{
Expand Down Expand Up @@ -2055,6 +2055,13 @@ auto ref choice(Range)(auto ref Range range)
"Choice did not return a valid element from the given Range");
}

@safe unittest // issue 18631
{
const a = [0,1,2];
auto r = choice(a);
auto s = choice(cast(const)[0,1,2]);
}

@safe unittest
{
import std.algorithm.searching : canFind;
Expand Down

0 comments on commit 4031411

Please sign in to comment.