I find vector::at() useful for alerting against out-of-bounds bugs while debugging, but it’s painfully slow and unsuited for release code. Is there a known compiler flag or some method to automatically convert vector::at() to vector::operator[] when compiling in release mode, sort of like how asserts() are stripped in release with DNDEBUG?
Edit:
Follow the linked question for a solution to this, or check the accepted answer (+ the comments below this question for some compiler specific stuff). Basically, this problem can be solved in reverse (there are options to allow bounds checking for vector::operator[] in debug mode).
>Solution :
If you want no bounds checking overhead at runtime, then use the subscript operator.
With most standard library implementations, you can enable non-standard bounds checking in subscript operator. Usually by defining a macro. This has a caveat, that the entire program must be compiled in the same mode, including any linked libraries.
Address/UB sanitisers should also be used when testing and debugging, and they may also detect typical buffer overflow conditions in absence of standard library support.