Skip to content

Commit

Permalink
Revert fix for 18631.
Browse files Browse the repository at this point in the history
The fix for 18631 broke code. Ranges cannot be marked with const or
inout in generic code. The range API does not require that any functions
be const or inout. In this case, with the changes, choice requires that
length and opSlice be const, breaking any code that uses a range with
choice that does not have a const length or opSlice (which is going to
be a large percentage of ranges with those functions which aren't
arrays).
  • Loading branch information
jmdavis committed Mar 23, 2018
1 parent b87d28f commit 5d6d784
Showing 1 changed file with 1 addition and 9 deletions.
10 changes: 1 addition & 9 deletions std/random.d
Expand Up @@ -2072,8 +2072,7 @@ Returns:
return a `ref` to the $(D range element), otherwise it will return
a copy.
*/
auto ref inout(ElementType!Range) choice(Range, RandomGen = Random)(inout auto ref Range range,
ref RandomGen urng)
auto ref choice(Range, RandomGen = Random)(auto ref Range range, ref RandomGen urng)
if (isRandomAccessRange!Range && hasLength!Range && isUniformRNG!RandomGen)
{
assert(range.length > 0,
Expand Down Expand Up @@ -2110,13 +2109,6 @@ 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 5d6d784

Please sign in to comment.