How to check for equality of two std::unordered_map using std::equal to check if both containers have same keys and their corresponding key values. Below my code prints unequal even though both containers have same size, set of keys and the corresponding key values are equal.
#include <iostream>
#include <unordered_map>
int main() {
std::unordered_map<char, int> um1, um2;
um1['f'] = 1;
um1['o'] = 1;
um1['r'] = 1;
um2['o'] = 1;
um2['r'] = 1;
um2['f'] = 1;
if (um1.size() == um2.size() && std::equal(um1.begin(), um1.end(), um2.begin()))
std::cout << "equal" << std::endl;
else
std::cout << "unequal" << std::endl;
}