std::hash (std::bitset)
来自cppreference.com
|
|
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
| template<size_t N> struct hash<bitset<N>>; |
(C++11 起) | |
std::hash为模板专门std::bitset<N>允许用户获取哈希的对象的类型std::bitset<N>.
Original:
The template specialization of std::hash for std::bitset<N> allows users to obtain hashes of objects of type std::bitset<N>.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[编辑] 为例
下面的代码显示了一种可能的哈希函数的输出上使用数位集
Original:
The following code shows one possible output of a hash function used on several bitsets:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
#include <iostream> #include <bitset> #include <functional> int main() { std::bitset<4> b1(1); std::bitset<4> b2(2); std::bitset<4> b3(b2); std::hash<std::bitset<4>> hash_fn; size_t h1 = hash_fn(b1); size_t h2 = hash_fn(b2); size_t h3 = hash_fn(b3); std::cout << h1 << '\n'; std::cout << h2 << '\n'; std::cout << h3 << '\n'; }
Output:
67918732 118251589 118251589
[编辑] 另请参阅
| (C++11) |
hash function object (类模板) |