GCC STL bound checking

2019-01-03 15:44发布

How do I enable bound checking for operator[] and iterators?

2条回答
The star\"
2楼-- · 2019-01-03 16:10

you should overload the operator[] for your specific classes. If you want to use an existing STL container, the at() function is a bounds-checked version of the operator[].

查看更多
我欲成王,谁敢阻挡
3楼-- · 2019-01-03 16:19

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()

查看更多
登录 后发表回答