3 ms·
C++ has had std::vector::at() - which checks for out-of-bounds indices - since C++98. The reason why it's not used all that much in practice is because indexing
by int_19h 4y ago
C++ has had std::vector::at() - which checks for out-of-bounds indices - since C++98. The reason why it's not used all that much in practice is because indexing is relatively rare - most of the time, you just iterate over collections, or otherwise use iterators rather than raw indices. And there's no ability to opt into bounds checking for C++ iterators in the standard - implementations usually provide some kind of checked iterators for debug builds, but performance is such that you'd never want that enabled for release.
- pjmlp 4y agoI always keep them enabled for release, performance is good enough. Most devs should learn to use profilers.
- int_19h 4y agoIn what implementation, and what guarantees does its debug iterators provide?
- tialaramex 4y ago> indexing is relatively rare This is also true in Rust for the same reason, arguably more true since Rust's built-in array type knows how big it is - but the observation in both languages programmers who want indexing write v[i] because that's the natural way to express what you meant, what's different isn't the frequency of need, only the language defaults. > performance is such that you'd never want that enabled for release. Let's make sure it's correct before we start worrying about performance https://twitter.com/magdraws/status/1551612747569299458 https://twitter.com/magdraws/status/1551612747569299458