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
1
u/sessamekesh Jul 30 '26
Right... I'm talking about vectors, and it does compile down to fancy dressing over a C-style allocation. https://godbolt.org/z/EGhrEvzoT
Regardless, I would argue in either case (overloaded or not) that bounds checking isn't "zero-cost". There are certainly cases where other mechanisms can provide safety (e.g. an example I gave in another comment, where the size of the dynamic structure is known to always exceed the width of the indexing type, e.g. `vec.size() > 256` and `operator[](...)` is invoked with a `uint8_t`.