The following code fails to compile:
assert("(((())))()()()()))".count!(c => c.among!('(', ')')) > 0);
With the error message:
"Error: template std.algorithm.searching.count cannot deduce function from argument types !((c) => c.among!('(', ')'))(string), candidates are..."
But the [standard library (http://dlang.org/phobos/std_algorithm_searching.html#.count) clearly shows that there is an overload of count
that takes a predicate, counting all element of R
for which the predicate returns true. So why does the compiler complain when I try to use count
this way?
assert("(((())))()()()()))".count!(c => c.among!('(', ')') != 0) > 0);
The problems are:
uint
instead of bool
(check the documentation for the return value of among
).