Boost logo

Boost :

From: Ed Brey (edbrey_at_[hidden])
Date: 2001-09-13 08:00:28


From: "Thomas Lien" <tgunlien_at_[hidden]>

> [...] A better way would be to
> decide at compile time whether or not you want to
> index check, possibly based on preprocessor values
> NDEBUG or perhaps INDEX_CHECKING.

You're in luck. This exact functionality is already exists. It's just a matter of choosing tools that provide your desired functionality. For example, to have have std::vector check operator[] in debug but not in release, you can use STLport and turn on the _STLP_DEBUG flag. For boost::array, since it just wraps an ordinary array, you can use one of several commercial runtime verification tools to catch indexing past array bounds at debug time.

As an added level of QoI, it probably would be a good idea to add asserts to boost::array so that a runtime verification tool is not necessary. Accordingly, the documentation would state that passing a paramater (which is unsigned) to array::operator[] that is not less than size() results in undefined behavior. Opinions?

As a side note, I noticed a couple typos in the array documentation: size_type is listed as signed, and difference_type as unsigned, which of course is reversed.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk