BDE 4.39.x Production Release
Loading...
Searching...
No Matches
bslh_hashthreadid

Detailed Description

Provide hashAppend for std::thread::id.

Outline

Purpose

Provide hashAppend for std::thread::id.

Description

This component provides a free function template, bslh::hashAppend, overloaded for the std::thread::id type. Including this function allows for std::thread::id (and types that contain members of that type) to be used as keys in BDE hashed containers.

Usage

This section illustrates intended usage of this component.

Example 1: Hashing a Thread ID

Suppose we have a struct with an int member and a std::thread::id member:

struct S {
int d_x;
std::thread::id d_tid;
};

To implement hashAppend for this struct, we would feed its first member, then its second, to hashAppend. This is made possible by the fact that this component provides an overload that accepts std::thread::id.

template <class t_HASH_ALG>
void hashAppend(t_HASH_ALG& algorithm, const S& s)
{
hashAppend(algorithm, s.d_x);
hashAppend(algorithm, s.d_tid);
}
bsl::enable_if<(bsl::is_integral< TYPE >::value||bsl::is_pointer< TYPE >::value||bsl::is_enum< TYPE >::value)&&!bsl::is_same< TYPE, bool >::value >::type hashAppend(HASH_ALGORITHM &hashAlg, TYPE input)
Definition bslh_hash.h:643

We can now use our new hashAppend overload:

void usageExample()
{
S s1;
s.d_x = 1;
s.d_tid = std::this_thread::get_id();
hashAppend(h1, s1);
S s2 = s1;
hashAppend(h2, s2);
assert(h1.computeHash() == h2.computeHash());
}
Definition bslh_defaulthashalgorithm.h:346
result_type computeHash()
Definition bslh_defaulthashalgorithm.h:431