std::hash<std::thread::id> (3) - Linux Manuals
std::hash<std::thread::id>: std::hash<std::thread::id>
Command to display std::hash<std::thread::id>
manual in Linux: $ man 3 std::hash<std::thread::id>
NAME
std::hash<std::thread::id> - std::hash<std::thread::id>
Synopsis
Defined in header <thread>
template<> struct hash<std::thread::id>; (since C++11)
The template specialization of std::hash for the std::thread::id class allows users to obtain hashes of the identifiers of threads.
Example
This section is incomplete
Reason: example that uses hash meaningfully
// Run this code
#include <iostream>
#include <thread>
#include <chrono>
#include <vector>
using namespace std::chrono_literals;
void foo()
{
std::this_thread::sleep_for(10ms);
}
int main()
{
std::vector<std::thread> v;
for(int n = 0; n < 4; ++n)
v.emplace_back(foo);
std::hash<std::thread::id> hasher;
for(auto& t : v) {
std::cout << "thread " << t.get_id() << " hashes to " << hasher(t.get_id()) << '\n';
t.join();
}
}
Possible output:
thread 139786440144640 hashes to 8905351942358389397
thread 139786431751936 hashes to 9222844670065909738
thread 139786423359232 hashes to 18199000599186780501
thread 139786414966528 hashes to 15386662774029264672
See also
hash hash function object
(class template)
(C++11)
Pages related to std::hash<std::thread::id>
- std::hash<std::type_index> (3) - std::hash<std::type_index>
- std::hash<std::error_code> (3) - std::hash<std::error_code>
- std::hash<std::error_condition> (3) - std::hash<std::error_condition>
- std::hash<std::experimental::optional> (3) - std::hash<std::experimental::optional>
- std::hash<std::optional> (3) - std::hash<std::optional>
- std::hash<std::unique_ptr> (3) - std::hash<std::unique_ptr>
- std::hash<std::variant> (3) - std::hash<std::variant>
- std::hash(std::bitset) (3) - std::hash(std::bitset)
- std::hash(std::experimental::observer_ptr) (3) - std::hash(std::experimental::observer_ptr)
- std::hash(std::experimental::propagate_const) (3) - std::hash(std::experimental::propagate_const)
- std::hash(std::experimental::shared_ptr) (3) - std::hash(std::experimental::shared_ptr)
- std::hash(std::experimental::string_view,std::experimental::wstring_view, (3) - std::hash(std::experimental::string_view,std::experimental::wstring_view,
- std::hash(std::experimental::string_view,std::experimental::wstring_view,std::experimental::u16string_view,std::experimental::u32string_view) (3) - std::hash(std::experimental::string_view,std::experimental::wstring_view,std::experimental::u16string_view,std::experimental::u32string_view)