Documentation of DList in std.container seems to be inaccurate
Koz Ross via Digitalmars-d
digitalmars-d at puremagic.com
Wed Nov 19 00:18:55 PST 2014
I just spent a good while debugging something which arose as a
result of the documentation of the DList's removeAny function.
More precisely, it seems that removeAny removes from the *back*,
rather than the front, as the documentation would indicate. To
quote the relevant page
(http://dlang.org/phobos/std_container.html#.DList):
T removeAny();
alias stableRemoveAny = removeAny;
Picks one value from the front of the container, removes it
from the container, and returns it.
Elements are not actually removed from the chain, but the
DList's, first/last pointer is advanced.
Precondition:
!empty
Returns:
The element removed.
Complexity:
Ο(1).
To demonstrate this, I give the following code:
import std.container, std.stdio;
DList!size_t foo;
foo.insertBack(1);
foo.insertBack(10);
auto x = foo.removeAny();
writeln(x);
According to the documentation, 1 should be printed. However,
instead, 10 gets printed. Am I completely insane, or is the
documentation just inaccurate?
I'm using GDC 4.9.1 for this.
More information about the Digitalmars-d
mailing list