August 26, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8590

           Summary: Documentation for "any" and "all" in std.algorithm is
                    incorrect
           Product: D
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody@puremagic.com
        ReportedBy: Philip.Daniels1971@gmail.com


--- Comment #0 from Philip Daniels <Philip.Daniels1971@gmail.com> 2012-08-26 09:03:45 PDT ---
Any: "Performs Ο(r.length) evaluations of pred."

This is incorrect, the function returns as soon as it finds an item matching pred.



All: "Performs Ο(r.length) evaluations of pred."

This is incorrect, the function returns as soon as it finds an item that does not match pred.


Both cases should be obvious from an examination of the code in std.algorithm, but here is a proof case anyway:


bool pred(int x)
{
    writeln("running pred");
    return x == 3;
}

void test_any()
{
    writeln("Testing any");
    int[] x = [1, 2, 3, 4, 5];
    auto a = any!(pred)(x);
}

void test_all()
{
    writeln("Testing all");
    int[] x = [1, 2, 3, 4, 5];
    auto a = all!(pred)(x);
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
August 26, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8590



--- Comment #1 from Philip Daniels <Philip.Daniels1971@gmail.com> 2012-08-26 09:09:05 PDT ---
Actually, since it's Big O it's *technically* correct, but I think it is confusing. Should read

"Performs between 0 and r.length evaluations of pred, returning as soon as a match is found".

and

"Performs between 0 and r.length evaluations of pred, returning as soon as a counterexample is found".

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------