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. uint代わりにラムダが返さboolれていること ( の戻り値については、ドキュメントを確認してくださいamong)。
  2. コンパイラ エラーが役に立たないこと。
于 2015-10-09T20:32:53.203 に答える