Right now most container (or container-like) classes have isEmpty () or empty () functions. Only very few have isNotEmpty () functions. This makes it hard to remember which class has what (even though modern IDEs help figure that out), but it leads to awfully inconsistent code.
if (container.isEmpty () == false)
seems super weird, when you’ve used
if ( conatiner.isNotEmpty ())
for other containers before.
Some container-like classes (e.g. MemoryOutputBuffer) don’t have either of these, so we have to resort to
if (output.getSize () != 0)
which seems super-strange, once you got used to isEmpty / isNotEmpty
Since these are so trivial (header-file only) changes. Would you mind if I contributed a few (that I noticed) via a pull request? Or do you want to do it yourself to make sure you got all of them? I admittedly don’t know enough of the code-base to catch them all. I would probably find only the most obvious ones.
So just for my information: do you agree that container-like classes (like the MemoryOutputBuffer etc.) also should have these functions, or is that too weird to you?
i would argue that technically there is no difference between a vector and a MemoryOutputBuffer, but maybe you have a different perspective?
No! It’s very bad form to use size() unless you really need to know the number it returns.
Most containers have an empty() method, but if not then the best way to check for emptiness would be v.begin() == v.end(). Calling something like deque.size() is very very inefficient.