c.among!('(', ')')) > 0); 错误信息: "Error: template s-6ren">
gpt4 book ai didi

d - 为什么我不能将 std.algorithm.count 与谓词函数一起使用

转载 作者:行者123 更新时间:2023-12-02 07:25:17 25 4
gpt4 key购买 nike

以下代码编译失败:

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 ) 清楚地表明有一个 count 的重载,它接受一个谓词,计算谓词所针对的 R 的所有元素返回真。那么为什么当我尝试以这种方式使用 count 时编译器会报错呢?

最佳答案

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

问题是:

  1. 您的 lambda 返回 uint 而不是 bool(查看 among 返回值的文档)。
  2. 编译器错误没有帮助。

关于d - 为什么我不能将 std.algorithm.count 与谓词函数一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33046525/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com