I am writing a fairly complex application that makes heavy use of STL containers. The application has a single, relatively simple, performance sensitive section that iterates over multiple std::maps and is executed thousands of times. Testing has shown than compiling with checked iterators disabled (_SECURE_SCL set to 0) results in almost a 2x speedup of the program as a whole, entirely concentrated in this section.
However, I cannot compile the application with _SECURE_SCL set to 0 because need to link with libraries that were compiled with _SECURE_SCL enabled and mixing _SECURE_SCL settings leads to problems. Also, I find it rather silly to use unchecked iterators in the entire application, when all the performance sensitive bits happen in a single screenful of code. That would be tantamount to tossing out the baby with the bathwater.
What options do I have to selectively use unchecked iterators for performance sensitive code/containers while maintaining compatibility with libraries compiled with checked iterators?
This works for me: