Any C++ experts in my timeline? Here's a problem: I have some code that uses a vector and references the start of the buffer with &v[0]. Seems to be common practice. However in some situations the vector is of size zero.
Conversation
Replying to
Using an iterator and comparing with end before using it. Using vec.begin() with a zero size array is fine though, just not dereferencing it since it already equals vec.end(). Maybe those functions should be getting passed a pair of iterators or a range, not a pointer and a size.
There's std::vector::data() instead of the &v[0] anti-pattern but using a pointer and pointer arithmetic to access a collection isn't idiomatic C++. Iterators are the old idiomatic style and ranges are the new modern style.

