Re:Does Rust's array bounds checking affect performance (2017)?
by expnkx on Monday July 12, 2021 @04:57PM
(#27815040)
If you want safety. you can just use _GLIBCXX_ASSERTIONS
https://godbolt.org/z/eThdeW3Mv
It gives you all bounds checking you need.
In fact, a lot of Linux distributions (like Fedora) built all packages with _GLIBCXX_ASSERTIONS by default.
If you want to have 0 runtime checks, like the C++ example, you can
1) make it unsafe and actively dangerous, like the C++ version
2) change the API so minimum length is guaranteed (probably possible in rust, harder in C++)
3) have the function private/inline where sufficient length is known/can be deduced and the check will be omitted