5,321
edits
Line 592: | Line 592: | ||
<syntaxhighlight lang="C++"> | <syntaxhighlight lang="C++"> | ||
std::unordered_map<int, std::string> my_map; | std::unordered_map<int, std::string> my_map; | ||
my_map[5] = "hey"; // Fine as long as value is not a reference. | my_map[5] = "hey"; // Fine as long as value type is not a reference. | ||
my_map.insert({5, "hey"}); // Necessary if value is a reference. | my_map.insert({5, "hey"}); // Necessary if value type is a reference. | ||
my_map.find(5) != my_map.end(); | my_map.find(5) != my_map.end(); | ||
my_map.contains(5); // C++20 | my_map.contains(5); // C++20 |