2 ms·
Then just don't do that, because v.at(x) does exactly the same thing and is safe and requires a whopping 3 characters more to type.
by netr0ute 4y ago
Then just don't do that, because v.at(x) does exactly the same thing and is safe and requires a whopping 3 characters more to type.
- CJefferson 4y agoYes, but that is one of many, many small things you have to remember and never get wrong. I wonder how many C++ code bases never use v[x] on containers where it is undefined behaviour to go out of bounds? I've not seen one myself.
- saghm 4y agoLiterally all UB is avoidable if you just "don't do" the things that cause it, and yet it still happens all the time. You might be right that this specific source of UB might not be a large issue in practice, but there are so many different causes of it that overall the strategy of "just don't write code that causes UB" is empirically not effective at scale.