Conversation

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.
1
1
So we end up having calls to functions that will reference the vector buffer as a target with an expected output size of zero. But UBSAN will throw warnings, which kinda makes sense: there is no v[0] in a vector of size zero.
3
Replying to and
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.