It looks like equality comparisons are broken for both hash_set
and unordered_set
in Visual C++ 2010.
I implemented a naive equality function for unordered containers using the language from the standard quoted by Matthieu to verify that it's a bug (just to be sure):
template <typename UnorderedContainer>
bool are_equal(const UnorderedContainer& c1, const UnorderedContainer& c2)
{
typedef typename UnorderedContainer::value_type Element;
typedef typename UnorderedContainer::const_iterator Iterator;
typedef std::pair<Iterator, Iterator> IteratorPair;
if (c1.size() != c2.size())
return false;
for (Iterator it(c1.begin()); it != c1.end(); ++it)
{
IteratorPair er1(c1.equal_range(*it));
IteratorPair er2(c2.equal_range(*it));
if (std::distance(er1.first, er1.second) !=
std::distance(er2.first, er2.second))
return false;
// A totally naive implementation of is_permutation:
std::vector<Element> v1(er1.first, er1.second);
std::vector<Element> v2(er2.first, er2.second);
std::sort(v1.begin(), v1.end());
std::sort(v2.begin(), v2.end());
if (!std::equal(v1.begin(), v1.end(), v2.begin()))
return false;
}
return true;
}
It returns that hs1
and hs2
from your example are equal. (Somebody let me know if you spot a bug in that code; I didn't really test it extensively...)
I'll file a defect report on Microsoft Connect.