2

以下代码无法编译:

assert("(((())))()()()()))".count!(c => c.among!('(', ')')) > 0);

带有错误消息:

"Error: template std.algorithm.searching.count cannot deduce function from argument types !((c) => c.among!('(', ')'))(string), candidates are..."

但是[标准库(http://dlang.org/phobos/std_algorithm_searching.html#.count)清楚地表明,有一个谓词的重载,计算谓词返回true的count所有元素。R那么为什么当我尝试使用count这种方式时编译器会抱怨呢?

4

1 回答 1

7

assert("(((())))()()()()))".count!(c => c.among!('(', ')') != 0) > 0);

问题是:

  1. 您的 lambda 正在返回uint而不是bool(查看文档以获取 的返回值among)。
  2. 编译器错误没有帮助。
于 2015-10-09T20:32:53.203 回答