Skip to content

Commit

Permalink
Add hash<gsl::not_null<std::shared_ptr<T>>>
Browse files Browse the repository at this point in the history
  • Loading branch information
tekezo committed Nov 29, 2024
1 parent 5550590 commit b19d587
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/share/memory_utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,17 @@ inline std::weak_ptr<T> make_weak(gsl::not_null<std::shared_ptr<T>> p) {

} // namespace memory_utility
} // namespace krbn

namespace std {
// This definition is required to prevent the following error:
//
// ```
// error: call to deleted constructor of 'gsl::not_null_hash<gsl::not_null<shared_ptr<T>>>'
// ```
template <typename T>
struct hash<gsl::not_null<std::shared_ptr<T>>> final {
std::size_t operator()(const gsl::not_null<std::shared_ptr<T>>& value) const {
return std::hash<T>{}(*value);
}
};
} // namespace std

0 comments on commit b19d587

Please sign in to comment.