www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22582] New: [std.algorithm.count] predicate does not

https://issues.dlang.org/show_bug.cgi?id=22582

          Issue ID: 22582
           Summary: [std.algorithm.count] predicate does not implicitly
                    convert to bool
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: trivial
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: jlourenco5691 gmail.com

std.algorithm.count's predicate should implicitly convert the unary fun to bool
when applicable. As it stands it does not follow the same convention of other
ranges or methods in Phobos that take in a bool predicate.

```
import std;

void main()
{
    auto range = 10.iota.array;
    range.filter!"a.among(1, 2, 3)".walkLength.writeln;

    // this should not need a cast to bool
    // we also have canFind which takes a range and returns a bool, but that's
just an unneeded workaround for what should be accomplished with this
    range.count!"cast(bool)a.among(1, 2, 3)".writeln;
}
```

--
Dec 09 2021