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

前端 未结 8 1470
陌清茗
陌清茗 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:49

    Your code compiles on VS2010 SP1 (VC10), but it fails to compile with GCC g++ 4.7.2.

    However, you may want to consider boost::hash from Boost.Functional to hash a std::pair (with this addition, your code compiles also with g++).

    #include 
    #include 
    
    class A
    {
    private: 
        std::unordered_set< 
            std::pair, 
            boost::hash< std::pair > 
        > u_edge_;
    };
    

提交回复
热议问题