How to make std::vector’s operator[] compile doing bounds checking in DEBUG but not in RELEASE

Visual Studio 2005 and 2008 already do bounds-checking on operator[] by default, in both debug and release builds. The macro to control this behavior is _SECURE_SCL. Set it to 0 to disable bounds-checking. Their current plan in VS2010 is to disable bounds-checking by default in release builds, but keep it on in debug. (The macro … Read more

GCC STL bound checking

You can activate runtime iterator and bounds checking by compiling with -D_GLIBCXX_DEBUG. Also note that random-access containers provide the always bounds-checking at()-operation in addition to operator []. References: GCC STL debug mode: http://gcc.gnu.org/onlinedocs/libstdc++/manual/debug_mode_using.html#debug_mode.using.mode at() operation: std::vector::at(), std::deque::at() and std::array::at()