jeudi 26 février 2015

How to compare unordered_set of unordered_set of integers in c++?

I need to test two sets for equality in my unit test.



#include <unordered_set> bla bla bla


unordered_set<unordered_set<int>> exampleOutput;
unordered_set<int> firstCluster;
firstCluster.insert(1);
firstCluster.insert(2);
unordered_set<int> secondCluster;
secondCluster.insert(3);
secondCluster.insert(4);

unordered_set<unordered_set<int>> outputAsSet;
for (auto e: output) {
vector<int> cluster = e.toVector();
outputAsSet.insert(cluster.begin(), cluster.end());
}
TS_ASSERT_EQUALS(exampleOutput, outputAsSet);


Which gives me the error



opt/local/include/gcc48/c++/bits/hashtable_policy.h: In instantiation of 'struct std::__detail::_Hash_code_base, std::unordered_set, std::__detail::_Identity, std::hash >, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, true>':



My guess is that stl is too stupid compare set of sets, because it can't compute the hash inner set. But maybe I am wrong.


Of course I can write all comparisons by hand comparing each inner set with all others in exampleSet, but who wants to do that...


Aucun commentaire:

Enregistrer un commentaire