boost::uuids::uuid as a key in std::unordered_map?

后端 未结 1 526

I\'m using clang (CXX=\'clang++ -std=c++11 -stdlib=libc++\') on Mac OS X, with boost 1.53.0.

I want to use uuid as keys in unordered_map, but getting the following e

1条回答
  •  既然无缘
    2021-01-05 02:05

    Why bug in boost? You should specialize std::hash template for boost::uuid.

    #include 
    
    namespace std
    {
    
    template<>
    struct hash
    {
        size_t operator () (const boost::uuids::uuid& uid)
        {
            return boost::hash()(uid);
        }
    };
    
    }
    

    or, simply create unordered_map with boost::hash par

    std::unordered_map>
    

    or provide hash functor that satisfies requirements of std::hash (thanks to Praetorian).

    0 讨论(0)
提交回复
热议问题