mirror of
https://github.com/dlang/phobos.git
synced 2025-05-06 19:16:13 +03:00
Decrease template instantiation in std.algorithm.searching : all & any
Using LDC with optimizations enabled the end compiled result is the same.
This commit is contained in:
parent
3fcbc9bcc7
commit
a4d4e03a5e
1 changed files with 8 additions and 4 deletions
|
@ -124,9 +124,10 @@ template all(alias pred = "a")
|
||||||
{
|
{
|
||||||
static assert(is(typeof(unaryFun!pred(range.front))),
|
static assert(is(typeof(unaryFun!pred(range.front))),
|
||||||
"`" ~ pred.stringof[1..$-1] ~ "` isn't a unary predicate function for range.front");
|
"`" ~ pred.stringof[1..$-1] ~ "` isn't a unary predicate function for range.front");
|
||||||
import std.functional : not;
|
foreach (ref e; range)
|
||||||
|
if (!unaryFun!pred(e))
|
||||||
return find!(not!(unaryFun!pred))(range).empty;
|
return false;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,7 +172,10 @@ template any(alias pred = "a")
|
||||||
bool any(Range)(Range range)
|
bool any(Range)(Range range)
|
||||||
if (isInputRange!Range && is(typeof(unaryFun!pred(range.front))))
|
if (isInputRange!Range && is(typeof(unaryFun!pred(range.front))))
|
||||||
{
|
{
|
||||||
return !find!pred(range).empty;
|
foreach (ref e; range)
|
||||||
|
if (unaryFun!pred(e))
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue