mirror of
https://github.com/dlang/phobos.git
synced 2025-05-04 00:54:05 +03:00
fix issue 18470 - std.algorithm.splitter has frame access problems for custom preds
This commit is contained in:
parent
4d27f76bd0
commit
b5162ecc01
1 changed files with 19 additions and 2 deletions
|
@ -3758,7 +3758,7 @@ if (is(typeof(binaryFun!pred(r.front, s)) : bool)
|
||||||
import std.algorithm.searching : find;
|
import std.algorithm.searching : find;
|
||||||
import std.conv : unsigned;
|
import std.conv : unsigned;
|
||||||
|
|
||||||
static struct Result
|
struct Result
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
Range _input;
|
Range _input;
|
||||||
|
@ -3779,7 +3779,7 @@ if (is(typeof(binaryFun!pred(r.front, s)) : bool)
|
||||||
|
|
||||||
static if (isBidirectionalRange!Range)
|
static if (isBidirectionalRange!Range)
|
||||||
{
|
{
|
||||||
static size_t lastIndexOf(Range haystack, Separator needle)
|
size_t lastIndexOf(Range haystack, Separator needle)
|
||||||
{
|
{
|
||||||
import std.range : retro;
|
import std.range : retro;
|
||||||
auto r = haystack.retro().find!pred(needle);
|
auto r = haystack.retro().find!pred(needle);
|
||||||
|
@ -4104,6 +4104,23 @@ if (is(typeof(binaryFun!pred(r.front, s)) : bool)
|
||||||
assert(s.empty);
|
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
|
/// ditto
|
||||||
auto splitter(alias pred = "a == b", Range, Separator)(Range r, Separator s)
|
auto splitter(alias pred = "a == b", Range, Separator)(Range r, Separator s)
|
||||||
if (is(typeof(binaryFun!pred(r.front, s.front)) : bool)
|
if (is(typeof(binaryFun!pred(r.front, s.front)) : bool)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue