Bug 8590 – Documentation for "any" and "all" in std.algorithm is incorrect

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-08-26T09:03:00Z
Last change time
2015-06-09T05:14:48Z
Assigned to
nobody
Creator
Philip.Daniels1971

Comments

Comment #0 by Philip.Daniels1971 — 2012-08-26T09:03:45Z
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); }
Comment #1 by Philip.Daniels1971 — 2012-08-26T09:09:05Z
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".
Comment #2 by justin — 2014-06-06T16:36:17Z
The documentation for these functions now reads "Performs (at most) Ο(r.length) evaluations of pred."