Thread overview | |||||
---|---|---|---|---|---|
|
July 30, 2012 [Issue 8467] New: A different third signature for std.algorithm.count | ||||
---|---|---|---|---|
| ||||
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@puremagic.com ReportedBy: bearophile_hugs@eml.cc --- Comment #0 from bearophile_hugs@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: ------- |
July 30, 2012 [Issue 8467] A different third signature for std.algorithm.count | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | http://d.puremagic.com/issues/show_bug.cgi?id=8467 Andrei Alexandrescu <andrei@metalanguage.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED CC| |andrei@metalanguage.com Resolution| |WONTFIX --- Comment #1 from Andrei Alexandrescu <andrei@metalanguage.com> 2012-07-30 04:31:15 PDT --- Nice idea, but breaks existing code. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
July 30, 2012 [Issue 8467] A different third signature for std.algorithm.count | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | http://d.puremagic.com/issues/show_bug.cgi?id=8467 --- Comment #2 from bearophile_hugs@eml.cc 2012-07-30 09:09:08 PDT --- (In reply to comment #1) > Nice idea, but breaks existing code. Thank you for the answer. I think around there isn't much code uses that count() with no argument for its template, so not a lot of code is broken by this change. If you are not interested in this enhancement, then I have opened a related enhancement request, Issue 8472 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
Copyright © 1999-2021 by the D Language Foundation