GCC reserves the right to reject the code. The standard does not define a member hash
for std::thread::id
. C ++ 11, 30.3.1.1:
namespace std {
class thread::id {
public:
id() noexcept;
};
bool operator==(thread::id x, thread::id y) noexcept;
bool operator!=(thread::id x, thread::id y) noexcept;
bool operator<(thread::id x, thread::id y) noexcept;
bool operator<=(thread::id x, thread::id y) noexcept;
bool operator>(thread::id x, thread::id y) noexcept;
bool operator>=(thread::id x, thread::id y) noexcept;
template<class charT, class traits>
basic_ostream<charT, traits>&
operator<< (basic_ostream<charT, traits>& out, thread::id id);
// Hash support
template <class T> struct hash;
template <> struct hash<thread::id>;
}
So using std::hash<std::thread::id>()(std::this_thread::get_id())
is definitely a valid (actually the only valid) way to get a stream ID hash.
Angew
source
to share