klauss wrote:A pointer isn't a "fake" iterator, in fact the whole point of the iterator interface is to mimic pointers.
I did not say that pointers are fake iterators.
Instead, the problem is that CollideArray attempts to mimic the STL iterator idiom (e.g. an STL-like container, with iterator, begin() and end()), but it fails in this regard.
For STL containers, end() will return a sentinel that somehow indicates the end of the container, and begin() will return end() if the container is empty, so that begin() == end(). Now look at CollideArray. begin() returns NULL rather than end() when the array is empty, and end() returns a pointer to the sentinel. This means that begin() != end() when the array is empty. I am not saying that the code cannot be fixed; just that the it is odd.
Furthermore, begin() and end() are used incorrectly by CollideArray to check if an iterator is valid (see CollideArray::Iterable() for an example). Pointer comparison is extremely tricky business; relational pointer comparisons are not guaranteed to work if the pointer is pointing to something outside the container. See paragraph 5.9 [expr.rel] in the C++ standard for the pointer comparison rules. Now, on this account I am willing to admit that the C++ standard is odd (although in its defense, it inherited these rules from the C standard.)
klauss wrote:Now, the way in which that iterator is obtained in begin() truly is awkward... and probably rather bug-prone.
Indeed. That is what triggered me in the first place.