M
Matthias Hildebrand
Hello,
std::map< int, MyClass*> mymap;
it = mymap.find( somekey ) // here happen bad things
if( it != mymap.end() )
{
// do something useful with it->second
}
else
{
// do nothing
}
I traced a strange program crash (unhandled exception on windows,
something similar on Solaris) down to happen at the second line of
the code given above which contains the find(). After some
investigation I found out that it happens when the map is empty.
This behaviour could be reproduced on Windows 2k and XP using MSVC 6.0
and 7.0 and finally also on Solaris unsing the Sun CC 5.4.
I read the documentation as well as books and internet resources but I
could not find a single statement that on an empty map a find() must
not be performed.
Could anybody please give me some information whether this is correct
or at least well known behaviour? Did I miss something? I do not like
the idea of preceeding all "critical" find() with some statement like
if( ! mymap.empty() )...
Any comments would be appreciated! Thanks!
Matthias
std::map< int, MyClass*> mymap;
it = mymap.find( somekey ) // here happen bad things
if( it != mymap.end() )
{
// do something useful with it->second
}
else
{
// do nothing
}
I traced a strange program crash (unhandled exception on windows,
something similar on Solaris) down to happen at the second line of
the code given above which contains the find(). After some
investigation I found out that it happens when the map is empty.
This behaviour could be reproduced on Windows 2k and XP using MSVC 6.0
and 7.0 and finally also on Solaris unsing the Sun CC 5.4.
I read the documentation as well as books and internet resources but I
could not find a single statement that on an empty map a find() must
not be performed.
Could anybody please give me some information whether this is correct
or at least well known behaviour? Did I miss something? I do not like
the idea of preceeding all "critical" find() with some statement like
if( ! mymap.empty() )...
Any comments would be appreciated! Thanks!
Matthias