[Issue 8467] New: A different third signature for std.algorithm.count
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Jul 29 19:33:57 PDT 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8467
Summary: A different third signature for std.algorithm.count
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: enhancement
Priority: P2
Component: Phobos
AssignedTo: nobody at puremagic.com
ReportedBy: bearophile_hugs at eml.cc
--- Comment #0 from bearophile_hugs at eml.cc 2012-07-29 19:33:55 PDT ---
The third signature of std.algorithm.count() is:
http://dlang.org/phobos/std_algorithm.html#count
size_t count(alias pred = "true", Range)(Range r);
So this program is equivalent to using walkLength, and in my opinion this is
not so useful:
import std.algorithm: count;
void main() {
assert(count([0, 0, 1]) == 3);
}
I think a more useful default for that third form is something similar to:
size_t count(alias pred = "a", Range)(Range r);
So it counts the true values:
import std.algorithm: count;
void main() {
assert(count([0, 0, 1]) == 1);
}
But keep in mind that unlike Python in D even empty arrays are sometimes
"true", etc:
import std.algorithm: count;
void main() {
assert(count!"a"([(new int[1])[0..0]]) == 1);
}
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list