繁体   English   中英

boost :: uuids :: uuid作为std :: unordered_map中的键?

[英]boost::uuids::uuid as a key in std::unordered_map?

我在Mac OS X上使用clang(CXX ='clang ++ -std = c ++ 11 -stdlib = libc ++'),增强1.53.0。

我想在unordered_map中使用uuid作为键,但是会出现以下错误:

/usr/bin/../lib/c++/v1/type_traits:748:38: error: implicit instantiation of undefined template
      'std::__1::hash<boost::uuids::uuid>'
    : public integral_constant<bool, __is_empty(_Tp)> {};
                                 ^
/usr/bin/../lib/c++/v1/unordered_map:327:54: note: in instantiation of template class
      'std::__1::is_empty<std::__1::hash<boost::uuids::uuid> >' requested here
template <class _Key, class _Tp, class _Hash, bool = is_empty<_Hash>::value

...

/usr/bin/../lib/c++/v1/unordered_map:327:71: error: no member named 'value' in
      'std::__1::is_empty<std::__1::hash<boost::uuids::uuid> >'
template <class _Key, class _Tp, class _Hash, bool = is_empty<_Hash>::value
                                                     ~~~~~~~~~~~~~~~~~^

...

它是什么 - Boost中的一个错误,它使它与我的C ++ lib不兼容? 或者我做错了什么? 任何解决方法?

为什么提升中的bug? 你应该专门为boost::uuid std :: hash模板。

#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);
    }
};

}

或者,只需使用boost::hash par创建unordered_map

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

或提供满足std::hash要求的hash函子(感谢Praetorian)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM