Andrei Alexandrescu wrote:
Bill Baxter wrote:
On Tue, Jul 28, 2009 at 4:16 PM, bearophile<[email protected]>
wrote:
Another solution for D code (that I have used in my Set data
structure. But it contains a negation):
if (!b.length) {...}
The rationale for .empty is that .length could be an O(n) operation
for some containers, but .empty should always be O(1). So, the
negation of .length is not a general replacement for .empty.
Exactly.
Andrei
Damn, I was wrong here. If you can't define .length in O(1), just don't
define it. But that means it may not be defined :o). Iron logic, heh. If
you just want the length and don't mind the complexity, call walkLength.
Andrei