I work with LLVM and I am having problems with the following piece of code that I did not write:
static std::map<std::string, Value*> NamedValues; ... //Lots of other code Value *V = NamedValues["Demo string"]; return V ? V : ErrorV("V is not in NamedValues map.");
From what I understand in std :: map, it should never return a null pointer (unless it's from memory?), So it's hard for me to understand how V 0 indicates that V is not on the map. As with my program, an error always occurs here, but I canโt understand why. Any help on what's going on here?
std::map::operator [] , , , .
std::map::operator []
POD (, ) . , nullptr, .
nullptr
"Demo string" NamedValues["Demo string"];, , nullptr.
"Demo string"
NamedValues["Demo string"];
, , find + end:
find
end
if (map.find(yourKey) != map.end()){ //the key exists }
EDIT:@ShadowRanger, count .
count
if (map.count(yourKey)){ //the key exists }
[] . , .
, , nullptr , , .