mirror of
https://github.com/dlang/phobos.git
synced 2025-05-01 07:30:33 +03:00
Fixed: std.algorithm.findAdjacent() returns non-empty range if no matching pair is found.
This commit is contained in:
parent
8a50942419
commit
ac2b71d2e1
1 changed files with 12 additions and 2 deletions
|
@ -3327,10 +3327,10 @@ Range findAdjacent(alias pred = "a == b", Range)(Range r)
|
||||||
{
|
{
|
||||||
for (ahead.popFront; !ahead.empty; r.popFront, ahead.popFront)
|
for (ahead.popFront; !ahead.empty; r.popFront, ahead.popFront)
|
||||||
{
|
{
|
||||||
if (binaryFun!(pred)(r.front, ahead.front)) break;
|
if (binaryFun!(pred)(r.front, ahead.front)) return r;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return r;
|
return ahead;
|
||||||
}
|
}
|
||||||
|
|
||||||
unittest
|
unittest
|
||||||
|
@ -3341,6 +3341,16 @@ unittest
|
||||||
assert(p == [10, 10, 9, 8, 8, 7, 8, 9 ]);
|
assert(p == [10, 10, 9, 8, 8, 7, 8, 9 ]);
|
||||||
p = findAdjacent!("a < b")(a);
|
p = findAdjacent!("a < b")(a);
|
||||||
assert(p == [7, 8, 9]);
|
assert(p == [7, 8, 9]);
|
||||||
|
// empty
|
||||||
|
a = [];
|
||||||
|
p = findAdjacent(a);
|
||||||
|
assert(p.empty);
|
||||||
|
// not found
|
||||||
|
a = [ 1, 2, 3, 4, 5 ];
|
||||||
|
p = findAdjacent(a);
|
||||||
|
assert(p.empty);
|
||||||
|
p = findAdjacent!"a > b"(a);
|
||||||
|
assert(p.empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
// findAmong
|
// findAmong
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue