mirror of
https://github.com/dlang/phobos.git
synced 2025-04-30 23:20:29 +03:00
Add Issue 9578 workaround to std.algorithm.all
As a result `all` can now be used with nested predicates. Issue URL: http://d.puremagic.com/issues/show_bug.cgi?id=9578
This commit is contained in:
parent
e2692d1d0f
commit
b5ca2ef0c9
1 changed files with 6 additions and 1 deletions
|
@ -9838,13 +9838,18 @@ assert(!all!"a & 1"([1, 2, 3, 5, 7, 9]));
|
||||||
bool all(alias pred, R)(R range)
|
bool all(alias pred, R)(R range)
|
||||||
if (isInputRange!R && is(typeof(unaryFun!pred(range.front))))
|
if (isInputRange!R && is(typeof(unaryFun!pred(range.front))))
|
||||||
{
|
{
|
||||||
return find!(not!(unaryFun!pred))(range).empty;
|
// dmd @@@BUG9578@@@ workaround
|
||||||
|
// return find!(not!(unaryFun!pred))(range).empty;
|
||||||
|
bool notPred(ElementType!R a) { return !unaryFun!pred(a); }
|
||||||
|
return find!notPred(range).empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
assert(all!"a & 1"([1, 3, 5, 7, 9]));
|
assert(all!"a & 1"([1, 3, 5, 7, 9]));
|
||||||
assert(!all!"a & 1"([1, 2, 3, 5, 7, 9]));
|
assert(!all!"a & 1"([1, 2, 3, 5, 7, 9]));
|
||||||
|
int x = 1;
|
||||||
|
assert(all!(a => a > x)([2, 3]));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated. It will be removed in January 2013. Use std.range.SortedRange.canFind.
|
// Deprecated. It will be removed in January 2013. Use std.range.SortedRange.canFind.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue