I know that g++ (and MSVC) have switches that allow bounds checking on operator[] , unfortunately, to my knowledge, LLVM's libc++ doesn't have a complete implementation of such switches or debug code.
On my current project I have been using my own implementation of vector (that I wrote for portability a few years back) which doesn't throw exceptions and has assert based bounds checking on operator[] and at (in fact one calls the other and they behave identically as there are no exceptions).
I'm going to be handing over this code-base after I've finished my current program and it may be in use for a long time. Since I'm not supposed to be required to maintain it or anything I would rather be fully standard compliant everywhere and I don't feel that re-implementing a container is in the spirit of the standard, (I also highly doubt that my container is as good as one written by the libc++ or libstdc++ team).
Is there some preprocessor magic or similar that I can do to make operator[] behave like at() during debug (so it aborts due to an uncaught exception) and behave like operator[] when I disable this debug mode? (Project is fully C++14 supported)
assert(i < vector.size()); auto x = vector[i]; /* etc */. - Rapptzstd::vector- using its implementation - while customisingoperator[]to call thevector'sat()in debug builds. That still means having a name other thanstd::vectorhanging around, which isn't ideal.... - Tony Delroy