www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 8590] New: Documentation for "any" and "all" in std.algorithm is incorrect

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



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: -------
Aug 26 2012
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8590




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: -------
Aug 26 2012