std::hash<std::thread::id>
提供: cppreference.com
<tbody>
</tbody>
| ヘッダ <thread> で定義
|
||
template<> struct hash<std::thread::id>; |
(C++11以上) | |
テンプレート std::hash の std::thread::id クラスに対する特殊化は、ユーザがスレッド識別子のハッシュを取れるようにします。
例外
| 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();
}
}
出力例:
thread 139786440144640 hashes to 8905351942358389397
thread 139786431751936 hashes to 9222844670065909738
thread 139786423359232 hashes to 18199000599186780501
thread 139786414966528 hashes to 15386662774029264672
関連項目
(C++11) |
ハッシュ関数オブジェクト (クラステンプレート) |