Boost :: unordered_map - do you need to specify a custom hash function for hashing std :: set <int>?
I would like to use boost::unordered_map<key,value> , where key is std::set<int> . Since a set of integers is not a built-in type, I assumed that I had to provide my own hash function (or rather, I was thinking of using boost hash_range ).
However, now I tried to initialize a hash map like this without providing a hash function or an equality predicate - and gcc did not complain. What's going on here? Is the incentive tricky enough for STL hash containers? Will it be slower than if I used a custom hash function? How about using boost::hash_range ?
Thanks in advance.
According to the Boost documentation :
The default hash function is Boost.Hash.
And, according to the documentation for Boost.Hash , default hash functions are provided for standard containers. Therefore, the hash function already written for std::set already exists. Boost hash containers are not intelligent enough to know how hash sets are automatic, but they are smart enough to use an already implemented implementation.
Hope this helps!
The function boost::hash< Key > by default. According to his documentation
Since it is compatible with TR1, it will work with:
integers floats pointers stringsHe also implements the extension proposed by Peter Dimov in release 6.18 in the list of issues of the journal of technical extensions of the library (p. 63), this adds support for:
arrays std::pair the standard containers. extending boost::hash for custom types.
http://www.boost.org/doc/html/hash.html
So yes, boost is smart enough to have STL hash containers. If you don't know something specific to your particular case of using set , I doubt there is any point in providing your own hash function.