I am getting strange behavior from within the boost::unordered_map library (v1.45.0).
In my class I create an object:
boost::unordered_map<uint16, MyStruct *> bufferStructMap;
Then I initialize it in the constructor initialization list:
MyClass::MyClass () : bufferStructMap( ) { .... }
Then I try to pull something out of it using the method “at” (see API in link):
const uint16 bufferNumber = 1;
try {
MyStruct * ptr = ( this->bufferStructMap.at( bufferNumber ) );
}
catch ( std::out_of_range & e ){
//deal with exception
}
When the map is empty, the application aborts with the call to “bufferStructMap.at( … )”, even though the API says the only exception that can be thrown is a std::out_of_range.
Can anyone detect a problem with my code, or is this a boost bug?
Thanks!
Mark B is probably right. If not, it looks like a bug in Boost.
Although… Since std::tr1::unordered_map (and the C++0x version? not sure) does not provide at(), you might want to just use find().
…