[Issue 22582] New: [std.algorithm.count] predicate does not implicitly convert to bool

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Dec 9 16:22:07 UTC 2021


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 at puremagic.com
          Reporter: jlourenco5691 at 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;
}
```

--


More information about the Digitalmars-d-bugs mailing list