mardi 30 mai 2017

The C++ Standard doesn`t provide a hash for this type

I am trying to create a unordered-map using a pair as a key. This is something new for me so I followed some tutorials and I wrote this:

    struct pair_hash {
        template <class T1, class T2>
        std::size_t operator () (const std::pair<T1, T2> &p) const {
            auto h1 = std::hash<T1>{}(p.first);
            auto h2 = std::hash<T2>{}(p.second);

            return h1 ^ h2;
        }
    };

int wmain(int argc, wchar_t * argv[])
{
   {...}

    using Key = std::pair<DWORD, DWORDLONG>;
    std::unordered_map<Key, USN, pair_hash> mymap;


    std::pair<DWORD, DWORDLONG> mypair(dwVolSN, fileId);

    mymap.insert({ mypair, usn });

    std::unordered_map<Key, USN>::const_iterator got;
    got = mymap.find(mypair); // HERE I GET THE ERROR

    return 0

}

Aucun commentaire:

Enregistrer un commentaire