std::hash<std::bitset>
来自cppreference.com
在标头 <bitset> 定义
|
||
template< std::size_t N > struct hash<std::bitset<N>>; |
(C++11 起) | |
std::hash 对 std::bitset<N> 的模板特化允许用户获得 std::bitset<N> 类型的对象的散列。
示例
下列代码展示用于数个 bitset
上的散列函数的一种可能输出:
运行此代码
#include <bitset> #include <functional> #include <iostream> int main() { std::bitset<4> b1{0}, b2{42}; std::bitset<8> b3{0}, b4{42}; std::hash<std::bitset<4>> hash_fn4; std::hash<std::bitset<8>> hash_fn8; using bin64 = std::bitset<64>; std::cout << std::hex << bin64{hash_fn4(b1)} << " = " << hash_fn4(b1) << '\n' << bin64{hash_fn4(b2)} << " = " << hash_fn4(b2) << '\n' << bin64{hash_fn8(b3)} << " = " << hash_fn8(b3) << '\n' << bin64{hash_fn8(b4)} << " = " << hash_fn8(b4) << '\n'; }
可能的输出:
0110110100001001111011100010011011010101100001100011011000011001 = 6d09ee26d5863619 1111111101011100010110100000111000111110100000111011100011110000 = ff5c5a0e3e83b8f0 0110110100001001111011100010011011010101100001100011011000011001 = 6d09ee26d5863619 0101110000011100011110011010111011100110010000110100110001001101 = 5c1c79aee6434c4d
参阅
(C++11) |
散列函数对象 (类模板) |