以下代码无法编译:
assert("(((())))()()()()))".count!(c => c.among!('(', ')')) > 0);
Run Code Online (Sandbox Code Playgroud)
带有错误消息:
"Error: template std.algorithm.searching.count cannot deduce function from argument types !((c) => c.among!('(', ')'))(string), candidates are..."
Run Code Online (Sandbox Code Playgroud)
但是[标准库(http://dlang.org/phobos/std_algorithm_searching.html#.count)清楚地表明存在一个count
带谓词的重载,计算R
谓词返回true的所有元素.那么为什么编译器会在我尝试使用count
这种方式时抱怨?
小智 7
assert("(((())))()()()()))".count!(c => c.among!('(', ')') != 0) > 0);
问题是:
uint
而不是bool
(检查文档的返回值among
).