Skip to content

Commit

Permalink
Merge pull request #6522 from BBasile/issue-18470
Browse files Browse the repository at this point in the history
fix issue 18470 - std.algorithm.splitter has frame access problems for custom preds
merged-on-behalf-of: Jack Stouffer <jack@jackstouffer.com>
  • Loading branch information
dlang-bot authored Jun 5, 2018
2 parents cc58e8a + b5162ec commit a6bf2b6
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions std/algorithm/iteration.d
Original file line number Diff line number Diff line change
Expand Up @@ -3796,7 +3796,7 @@ if (is(typeof(binaryFun!pred(r.front, s)) : bool)
import std.algorithm.searching : find;
import std.conv : unsigned;

static struct Result
struct Result
{
private:
Range _input;
Expand All @@ -3817,7 +3817,7 @@ if (is(typeof(binaryFun!pred(r.front, s)) : bool)

static if (isBidirectionalRange!Range)
{
static size_t lastIndexOf(Range haystack, Separator needle)
size_t lastIndexOf(Range haystack, Separator needle)
{
import std.range : retro;
auto r = haystack.retro().find!pred(needle);
Expand Down Expand Up @@ -4142,6 +4142,23 @@ if (is(typeof(binaryFun!pred(r.front, s)) : bool)
assert(s.empty);
}

@safe unittest // issue 18470
{
import std.algorithm.comparison : equal;

const w = [[0], [1], [2]];
assert(w.splitter!((a, b) => a.front() == b)(1).equal([[[0]], [[2]]]));
}

@safe unittest // issue 18470
{
import std.algorithm.comparison : equal;
import std.ascii : toLower;

assert("abXcdxef".splitter!"a.toLower == b"('x').equal(["ab", "cd", "ef"]));
assert("abXcdxef".splitter!((a, b) => a.toLower == b)('x').equal(["ab", "cd", "ef"]));
}

/// ditto
auto splitter(alias pred = "a == b", Range, Separator)(Range r, Separator s)
if (is(typeof(binaryFun!pred(r.front, s.front)) : bool)
Expand Down

0 comments on commit a6bf2b6

Please sign in to comment.