Merge two unordered map:
#include <bits/stdc++.h>
using namespace std;
int main()
{
unordered_map<int, string> map1 = {{1, "a"}, {2, "b"}};
unordered_map<int, string> map2 = {{4, "x"}, {3, "y"}};
map1.merge(map2);
}
map1 contains {1:"a", 2:"b", 3:"y", 4:"x"}, map2 is empty
map1 contains {1:"a", 2:"b", 3:"y"}, map2 has {2:"x"}
map1 remains unchanged
Compilation error
This question is part of this quiz :
C++ Unordered Map