4

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!

0

1 Answer 1

8

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.