I have a c++ map where the value type is a bool
. I need to see if a key exists in the map, and if it doesn't, return false
. This is my code right now:
try {
return board.at[{x, y}];
}
catch (const std::out_of_range& oor) {
return false;
}
I don't want to use the []
operator because that will initialize the value if it doesn't exist. Is there any way to see if the value exists in the map without a try block?