From 4eb7c3210fc04b8fc92d99b6dfe5323596c63593 Mon Sep 17 00:00:00 2001 From: Danil Sidoruk Date: Thu, 12 Sep 2024 21:09:41 +0300 Subject: [PATCH] Implement std::hash for boost::fibers::context::id --- include/boost/fiber/context.hpp | 12 ++++++++++++ src/context.cpp | 10 ++++++++++ 2 files changed, 22 insertions(+) diff --git a/include/boost/fiber/context.hpp b/include/boost/fiber/context.hpp index 8a96c4cc..82d84840 100644 --- a/include/boost/fiber/context.hpp +++ b/include/boost/fiber/context.hpp @@ -174,6 +174,7 @@ private: public: class id { private: + friend std::hash; context * impl_{ nullptr }; public: @@ -520,6 +521,17 @@ static intrusive_ptr< context > make_worker_context( launch policy, }} +// std::hash specialization +namespace std { + +template <> +struct hash< ::boost::fibers::context::id > { + std::size_t + operator() ( ::boost::fibers::context::id const& id ) const noexcept; +}; + +} + #ifdef _MSC_VER # pragma warning(pop) #endif diff --git a/src/context.cpp b/src/context.cpp index 4f9eabc3..97a45a50 100644 --- a/src/context.cpp +++ b/src/context.cpp @@ -434,6 +434,16 @@ context::attach( context * ctx) noexcept { }} +namespace std { + +std::size_t +hash< ::boost::fibers::context::id >::operator() ( ::boost::fibers::context::id const& id ) const noexcept { + return reinterpret_cast(id.impl_); +} + +} + + #ifdef BOOST_HAS_ABI_HEADERS # include BOOST_ABI_SUFFIX #endif