为什么可以';我将std.algorithm.count与谓词函数一起使用

为什么可以';我将std.algorithm.count与谓词函数一起使用,d,phobos,D,Phobos,以下代码无法编译: assert("(((())))()()()()))".count!(c => c.among!('(', ')')) > 0); 出现以下错误消息: "Error: template std.algorithm.searching.count cannot deduce function from argument types !((c) => c.among!('(', ')'))(string), candidates are..." 但是[sta

以下代码无法编译:

assert("(((())))()()()()))".count!(c => c.among!('(', ')')) > 0);
出现以下错误消息:

"Error: template std.algorithm.searching.count cannot deduce function from argument types !((c) => c.among!('(', ')'))(string), candidates are..."
但是[standard library()清楚地表明有一个超负荷的
count
接受一个谓词,计算谓词返回true的
R
的所有元素。那么,当我试图以这种方式使用
count
时,为什么编译器会抱怨?

断言(((((())())”.count!(c=>c.interest!(“(”(“,”),“)”)!=0)>0);

问题是:

  • 您的lambda返回的是
    uint
    而不是
    bool
    (检查文档中的
    返回值)
  • 编译器错误没有帮助

  • 奇怪的是,模板约束明确地说
    是(typeof(unaryFun!pred(haystack.front)):bool)
    。我本以为
    是(uint:bool)
    会返回true,但我想不会。