c++ - boost::uuids::uuid as a key in std::unordered_map? -
i'm using clang (cxx='clang++ -std=c++11 -stdlib=libc++') on mac os x, boost 1.53.0.
i want use uuid keys in unordered_map, getting following errors:
/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 ~~~~~~~~~~~~~~~~~^
...
what - bug in boost, makes incompatible c++ lib? or doing wrong? workarounds?
why bug in boost? should specialize std::hash template 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, create unordered_map
boost::hash
par
std::unordered_map<boost::uuids::uuid, t, boost::hash<boost::uuids::uuid>>
or provide hash
functor satisfies requirements of std::hash
(thanks praetorian).
Comments
Post a Comment