How rigorous is the bounds checking on vectors compared to heap arrays? How exactly is it checking bounds and how does that compare with how a heap array is checked?
How rigorous is the bounds checking on vectors compared to heap arrays? How exactly
Share
A
vectorwill do bounds checking if you use theat()function, for example:However, if you use
operator[], there is no bounds checking. (And accessing non-existent elements leads to undefined behavior.)It should be noted, though, that most implementations will have the possibility to include bounds-checking on all iterators, which is discussed in the answers here. By default, VS2008 and below have it on in Debug and Release, VS2010 does only in Debug. gcc requires you define
_GLIBCXX_DEBUGto get checked iterators.