Building an unordered map with tuples as keys

前端 未结 6 995
南方客
南方客 2021-02-01 05:40

In a C++ program with Boost, I am trying to build an unordered map whose keys are tuples of doubles:

typedef boost::tuples::tuple

        
6条回答
  •  囚心锁ツ
    2021-02-01 06:16

    Have you tried using this:

    #include "boost/functional/hash.hpp"
    #include 
    #include 
    
    using Edge = std::tuple;
    
    struct KeyHash {
        std::size_t operator()(const Edge & key) const {
            return boost::hash_value(key);
        }
    };
    
    using EdgeMap = std::unordered_map;
    
    

    please notice I am using std for tuple and unordered_map.

    You can see full code with using even lambda on this Compiler Explorer link.

提交回复
热议问题