[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:
Nick Treleaven 2023-04-10 17:10:18 +01:00 committed by GitHub
parent 128f75181c
commit 01a12f919e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -119,12 +119,9 @@ template all(alias pred = "a")
Performs (at most) $(BIGOH range.length) evaluations of `pred`.
+/
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;
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`.
+/
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;
}