Creating an std::unordered_map with an std::pair as key

后端 未结 2 833
情歌与酒
情歌与酒 2020-12-14 18:52

I am trying to create an std::unordered_map with an std::pair as key. As you can imagine, this would require me to explicitly provide a class to generate a hash for a given

2条回答
  •  旧时难觅i
    2020-12-14 19:18

    Apparently, libstdc++ refers to your hash object via const PairHash*. Thus calling the operator () which is not marked const in your program is a compiler error.

    You can get your code to compile with libstdc++ by making operator() const.

    As of 17.6.3.4 (Hash Requirements), a Hash type must provide a size_t operator(KeyType) const;, so your code is indeed incorrect.

提交回复
热议问题