I declare an unordered_map
as following:
boost::unordered_map<std::array<char, 20>, t_torrent> torrent_ins;
and then insert an element into it (in the case the key hasn't existed, this map will return a reference for the new element)
t_torrent& torrent_in = torrent_ins[to_array<char,20>(in)];
But I got an error message:
../src/Tracker/torrent_serialization.cpp:30: instantiated from here/usr/local/include/boost/functional/hash/extensions.hpp:176: error: no matching function for call to ‘hash_value(const std::array<char, 20ul>&)’
Could you guys help me explain this error? Thanks so much!
It's because there's no "default" hashing function for std::array<char, 20>
, at least none that the implementation furnishes. You must supply your hashing function for std::array<char, 20>
then for your code to work.
As you can see in std::unordered_map,:
template<
class Key,
class T,
class Hash = std::hash<Key>,
class KeyEqual = std::equal_to<Key>,
class Allocator = std::allocator< std::pair<const Key, T> >
> class unordered_map;
you must provide Hash
for type Key
to provide your custom hash function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With