How can I make an unordered set of pairs of integers in C++?

前端 未结 8 1473
陌清茗
陌清茗 2020-12-08 00:16

The following program does not compile an unordered set of pairs of integers, but it does for integers. Can unordered_set and its member functions be used on us

8条回答
  •  忘掉有多难
    2020-12-08 00:51

    You are missing a hash function for std::pair>. For example,

    struct bad_hash
    {
      std::size_t operator()(const std::pair& p) const
      {
        return 42;
      }
    };
    
    ....
    
    std::unordered_set< std::pair, bad_hash> u_edge_;
    

    You can also specialize std::hash for std::hash>, in which case you can omit the second template parameter.

提交回复
热议问题