Commit 1fad944d authored by Kirill Smelkov's avatar Kirill Smelkov

libgolang: Provide std::hash for chan

Without defined std::hash it is not possible to use channels as keys in
dict or set. We will be using set<chan> in os/signal package
implementation.

/reviewed-on !17
parent 60de9538
#ifndef _NXD_LIBGOLANG_H
#define _NXD_LIBGOLANG_H
// Copyright (C) 2018-2020 Nexedi SA and Contributors.
// Copyright (C) 2018-2022 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This program is free software: you can Use, Study, Modify and Redistribute
......@@ -808,15 +808,23 @@ typedef refptr<_errorWrapper> errorWrapper;
} // golang::
// std::hash<refptr>
// std::
namespace std {
// std::hash<refptr>
template<typename T> struct hash<golang::refptr<T>> {
std::size_t operator()(const golang::refptr<T>& p) const noexcept {
return hash<T*>()(p._ptr());
}
};
// std::hash<chan>
template<typename T> struct hash<golang::chan<T>> {
std::size_t operator()(const golang::chan<T>& ch) const noexcept {
return hash<void*>()(reinterpret_cast<void*>(ch._rawchan()));
}
};
} // std::
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment