Skip to content

Commit

Permalink
[Issue 16073] Fix incorrect uses of random access range primitives in…
Browse files Browse the repository at this point in the history
… std.algorithm.searching
  • Loading branch information
JackStouffer committed Jun 2, 2016
1 parent 3a1db06 commit 74398e7
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions std/algorithm/searching.d
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ if (isInputRange!(Range) && is(typeof(r.front == lPar)))
*/
BoyerMooreFinder!(binaryFun!(pred), Range) boyerMooreFinder
(alias pred = "a == b", Range)
(Range needle) if (isRandomAccessRange!(Range) || isSomeString!Range)
(Range needle) if ((isRandomAccessRange!(Range) && hasSlicing!Range) || isSomeString!Range)
{
return typeof(return)(needle);
}
Expand Down Expand Up @@ -1768,14 +1768,14 @@ if (isForwardRange!R1 && isForwardRange!R2

/// ditto
R1 find(alias pred = "a == b", R1, R2)(R1 haystack, R2 needle)
if (isRandomAccessRange!R1 && isBidirectionalRange!R2
if (isRandomAccessRange!R1 && hasLength!R1 && hasSlicing!R1 && isBidirectionalRange!R2
&& is(typeof(binaryFun!pred(haystack.front, needle.front)) : bool))
{
if (needle.empty) return haystack;
const needleLength = walkLength(needle.save);
if (needleLength > haystack.length)
{
return haystack[$ .. $];
return haystack[haystack.length .. haystack.length];
}
// @@@BUG@@@
// auto needleBack = moveBack(needle);
Expand Down Expand Up @@ -2573,7 +2573,7 @@ if (isForwardRange!R1 && isForwardRange!R2)
}

static if (isSomeString!R1 && isSomeString!R2
|| isRandomAccessRange!R1 && hasLength!R2)
|| (isRandomAccessRange!R1 && hasSlicing!R1 && hasLength!R1 && hasLength!R2))
{
auto balance = find!pred(haystack, needle);
immutable pos1 = haystack.length - balance.length;
Expand Down Expand Up @@ -2637,7 +2637,7 @@ if (isForwardRange!R1 && isForwardRange!R2)
}

static if (isSomeString!R1 && isSomeString!R2
|| isRandomAccessRange!R1 && hasLength!R2)
|| (isRandomAccessRange!R1 && hasLength!R1 && hasSlicing!R1 && hasLength!R2))
{
auto balance = find!pred(haystack, needle);
immutable pos = haystack.length - balance.length;
Expand Down Expand Up @@ -2697,7 +2697,7 @@ if (isForwardRange!R1 && isForwardRange!R2)
}

static if (isSomeString!R1 && isSomeString!R2
|| isRandomAccessRange!R1 && hasLength!R2)
|| isRandomAccessRange!R1 && hasLength!R1 && hasSlicing!R1 && hasLength!R2)
{
auto balance = find!pred(haystack, needle);
immutable pos = balance.empty ? 0 : haystack.length - balance.length + needle.length;
Expand Down Expand Up @@ -3315,7 +3315,7 @@ Range minPos(alias pred = "a < b", Range)(Range range)
pos = i;
}
}
return range[pos .. $];
return range[pos .. range.length];
}
else
{
Expand Down

0 comments on commit 74398e7

Please sign in to comment.