std::hash (std::bitset)

From cppreference.com
< cpp‎ | utility‎ | bitset
 
 
Utilities library
Type support (basic types, RTTI, type traits)
Dynamic memory management
Error handling
Program utilities
Variadic functions
Date and time
Function objects
(C++11)
Relational operators
Optional and any
(C++17)
(C++17)
Pairs and tuples
(C++11)
(C++17)
Swap, forward and move
(C++14)
(C++11)
(C++11)
Type operations
(C++11)
(C++17)
 
 
template<size_t N> struct hash<bitset<N>>;
(since C++11)

The template specialization of std::hash for std::bitset<N> allows users to obtain hashes of objects of type std::bitset<N>.

[edit] Example

The following code shows one possible output of a hash function used on several bitsets:

#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

[edit] See also

(C++11)
hash function object
(class template)