r/cpp • u/pavel_v • Jul 29 '26
C++26: Reducing undefined behaviour
https://www.sandordargo.com/blog/2026/07/29/cpp26-reduces-undefined-behaviour
89
Upvotes
r/cpp • u/pavel_v • Jul 29 '26
View all comments
Show parent comment
2
u/sessamekesh Jul 29 '26
It can be, I personally wouldn't consider bounds checking to be part of the cost of a pointer dereference (which is, under the hood, what
vec[k]is).I have similar feelings about other things like zeroing out newly allocated memory. Safety might be the appropriate default and the correct thing to do 95% of the time, but you're certainly going to have outliers where the safety work (which is real even if trivial runtime cost) is redundant or otherwise undesirable.