mirror of
https://github.com/dlang/phobos.git
synced 2025-04-30 15:10:46 +03:00
[std.algorithm.searching] Don't instantiate template pred in all
and any
constraints (#8715)
Fixes Issue 23769 - Lambda isn't a unary predicate for lambda that doesn't compile.
This commit is contained in:
parent
128f75181c
commit
01a12f919e
1 changed files with 4 additions and 6 deletions
|
@ -119,12 +119,9 @@ template all(alias pred = "a")
|
||||||
Performs (at most) $(BIGOH range.length) evaluations of `pred`.
|
Performs (at most) $(BIGOH range.length) evaluations of `pred`.
|
||||||
+/
|
+/
|
||||||
bool all(Range)(Range range)
|
bool all(Range)(Range range)
|
||||||
if (isInputRange!Range)
|
if (isInputRange!Range &&
|
||||||
|
(__traits(isTemplate, pred) || is(typeof(unaryFun!pred(range.front)))))
|
||||||
{
|
{
|
||||||
static assert(is(typeof(unaryFun!pred(range.front))),
|
|
||||||
"`" ~ (isSomeString!(typeof(pred))
|
|
||||||
? pred.stringof[1..$-1] : pred.stringof)
|
|
||||||
~ "` isn't a unary predicate function for range.front");
|
|
||||||
import std.functional : not;
|
import std.functional : not;
|
||||||
|
|
||||||
return find!(not!(unaryFun!pred))(range).empty;
|
return find!(not!(unaryFun!pred))(range).empty;
|
||||||
|
@ -172,7 +169,8 @@ template any(alias pred = "a")
|
||||||
Performs (at most) $(BIGOH range.length) evaluations of `pred`.
|
Performs (at most) $(BIGOH range.length) evaluations of `pred`.
|
||||||
+/
|
+/
|
||||||
bool any(Range)(Range range)
|
bool any(Range)(Range range)
|
||||||
if (isInputRange!Range && is(typeof(unaryFun!pred(range.front))))
|
if (isInputRange!Range &&
|
||||||
|
(__traits(isTemplate, pred) || is(typeof(unaryFun!pred(range.front)))))
|
||||||
{
|
{
|
||||||
return !find!pred(range).empty;
|
return !find!pred(range).empty;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue