Bug 22582 – [std.algorithm.count] predicate does not implicitly convert to bool

Status
RESOLVED
Resolution
FIXED
Severity
trivial
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2021-12-09T16:22:07Z
Last change time
2021-12-10T15:16:51Z
Assigned to
No Owner
Creator
João Lourenço

Comments

Comment #0 by jlourenco5691 — 2021-12-09T16:22:07Z
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; } ```
Comment #1 by dlang-bot — 2021-12-09T16:29:01Z
@iK4tsu created dlang/phobos pull request #8330 "Issue 22582 - [std.algorithm.count] predicate does not implicitly convert to bool" mentioning this issue: - std.algorithm.searching.count: Fix predicate not implicitly converting to bool Issue 22582 - [std.algorithm.count] predicate does not implicitly convert to bool Signed-off-by: João Lourenço <[email protected]> https://github.com/dlang/phobos/pull/8330
Comment #2 by dlang-bot — 2021-12-10T15:16:51Z
dlang/phobos pull request #8330 "Issue 22582 - [std.algorithm.count] predicate does not implicitly convert to bool" was merged into master: - 6974482f73182bc5d604ec4834b16ade62a3d689 by João Lourenço: std.algorithm.searching.count: Fix predicate not implicitly converting to bool Fix Issue 22582 - [std.algorithm.count] predicate does not implicitly convert to bool Signed-off-by: João Lourenço <[email protected]> https://github.com/dlang/phobos/pull/8330