문제

I'm wondering if there's some efficient way to hash std::bitset or boost::dynamic_bitset<> for Boost's unordered containers?

I'm currently converting std::bitset or boost::dynamic_bitset<> to std::string first before hashing them, but it seems this is going to be slow.

Is there some better way?

도움이 되었습니까?

해결책

The C++11 requires standard library to have std::hash<std::bitset> specialized. IOW it should have hash already.

For boost you should use config: #define BOOST_DYNAMIC_BITSET_DONT_USE_FRIENDS then the dynamic_bitset::m_bits member becomes public and you can make hash on it.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top