www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 8467] New: A different third signature for std.algorithm.count

reply d-bugmail puremagic.com writes:
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



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: -------
Jul 29 2012
next sibling parent d-bugmail puremagic.com writes:
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



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: -------
Jul 30 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8467





 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: -------
Jul 30 2012