The C++ Standard Library - A Tutorial and Reference, 2nd Edition refers to safe versions of the STL which support various utilities such as runtime bounds checking for
Thus, it is a good idea to use a "safe" STL, at least during software
development. A first version of a safe STL was introduced by Cary Horstmann (see [SafeSTL]). Another example is the "STLport", which is
available for free for almost any platform at [STLPort]. In addition,
library vendors now provide flags to enable a "safer" mode, which
especially should be enabled during development.
libstdc++ has a debug mode, which can be enabled by defining
_GLIBCXX_DEBUG when compiling.
The libstdc++ debug mode performs checking for many areas of the C++ standard, but the focus is on checking interactions among standard iterators, containers, and algorithms, including:
Safe iterators: Iterators keep track of the container whose elements they reference, so errors such as incrementing a past-the-end iterator or dereferencing an iterator that points to a container that has been destructed are diagnosed immediately.
Algorithm preconditions: Algorithms attempt to validate their input parameters to detect errors as early as possible. For instance, the
set_intersectionalgorithm requires that its iterator parameters
last1form a valid iterator range, and that the sequence
[first1, last1)is sorted according to the same predicate that was passed to set_intersection; the libstdc++ debug mode will detect an error if the sequence is not sorted or was sorted by a different predicate.
Bounds checking in
operator is included.