What is a==b supposed to do for two hash_sets?

Chris Jefferson caj@cs.york.ac.uk
Tue Feb 1 21:14:00 GMT 2005


Lorenz Minder wrote:
> Hi,
> 
> I was reading through the code of hash_set, when I spotted something
> which looks really odd to me: Comparison of two hash_sets is done by
> comparing the buckets one by one. To give the simplest possible example,
> doing
> 
> 	#include <iostream>
> 	#include <ext/hash_set>
> 
> 	int main(void)
> 	{
> 		__gnu_cxx::hash_set<int> x(1000), y;
> 		std::cout << "x empty ? " << x.empty() << '\n';
> 		std::cout << "y empty ? " << y.empty() << '\n';
> 		std::cout << "x == y  ? " << (x == y) << '\n';
> 
> 		return 0;
> 	}
> 
> gives the output:
> 
> 	x empty ? 1
> 	y empty ? 1
> 	x == y  ? 0
> 
> I think this is wrong: My feeling is that two hash_sets should be
> considered equal iff they contain the same elements. I can't find any
> statement saying so though, neither in SGI's documentation nor
> elsewhere.
> 
> Is this a bug? Should I file a PR?
> 

One interesting point to note is that the unordered_set and company in 
TR1 don't have == defined on them because it is quite hard to implement 
efficently, particularily on multisets, although that doesn't help with 
this bug right now...

Chris



More information about the Libstdc++ mailing list