C++20 gives us std::map::contains
to do that.
#include <iostream>#include <string>#include <map>int main(){ std::map<int, std::string> example = {{1, "One"}, {2, "Two"}, {3, "Three"}, {42, "Don\'t Panic!!!"}}; if(example.contains(42)) { std::cout << "Found\n"; } else { std::cout << "Not found\n"; }}