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

后端 未结 1 528

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 <boost/functional/hash.hpp>
    
    namespace std
    {
    
    template<>
    struct hash<boost::uuids::uuid>
    {
        size_t operator () (const boost::uuids::uuid& uid)
        {
            return boost::hash<boost::uuids::uuid>()(uid);
        }
    };
    
    }
    

    or, simply create unordered_map with boost::hash par

    std::unordered_map<boost::uuids::uuid, T, boost::hash<boost::uuids::uuid>>
    

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

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