From 9383d29187d117d846f6db72cbcc980489b289c6 Mon Sep 17 00:00:00 2001 From: Harald Fernengel Date: Mon, 19 May 2025 13:03:04 +0200 Subject: [PATCH] Allow CancellationContext in hashes A hash needs a hashing function and a way to determin equality. Since we don't want to add a comparison operator, let's add another helper so we can store CancellationContext in std::unordered_set and friends. Relates-To: MINOR Signed-off-by: Harald Fernengel --- .../olp/core/client/CancellationContext.h | 17 +++++++++++++++++ .../olp/core/client/CancellationContext.inl | 5 +++++ 2 files changed, 22 insertions(+) diff --git a/olp-cpp-sdk-core/include/olp/core/client/CancellationContext.h b/olp-cpp-sdk-core/include/olp/core/client/CancellationContext.h index fbefe2979..1968730b4 100644 --- a/olp-cpp-sdk-core/include/olp/core/client/CancellationContext.h +++ b/olp-cpp-sdk-core/include/olp/core/client/CancellationContext.h @@ -83,6 +83,7 @@ class CORE_API CancellationContext { private: /// A helper for unordered containers. friend struct CancellationContextHash; + friend struct CancellationContextEquality; /** * @brief An implementation used to shared the `CancellationContext` instance. @@ -126,6 +127,22 @@ struct CORE_API CancellationContextHash { size_t operator()(const CancellationContext& context) const; }; +/** + * @brief A helper for unordered containers for equality comparison + */ +struct CORE_API CancellationContextEquality { + /** + * @brief Checks equality for two `CancellationContext` instances. + * + * @param lhs The first `CancellationContext` instance. + * @param rhs The second `CancellationContext` instance. + * + * @return True if both refer to the same implementation; false otherwise. + */ + bool operator()(const CancellationContext& lhs, + const CancellationContext& rhs) const; +}; + } // namespace client } // namespace olp diff --git a/olp-cpp-sdk-core/include/olp/core/client/CancellationContext.inl b/olp-cpp-sdk-core/include/olp/core/client/CancellationContext.inl index e19aeefb2..2d58fc903 100644 --- a/olp-cpp-sdk-core/include/olp/core/client/CancellationContext.inl +++ b/olp-cpp-sdk-core/include/olp/core/client/CancellationContext.inl @@ -79,5 +79,10 @@ inline size_t CancellationContextHash::operator()( context.impl_); } +inline bool CancellationContextEquality::operator()( + const CancellationContext& lhs, const CancellationContext& rhs) const { + return lhs.impl_ == rhs.impl_; +} + } // namespace client } // namespace olp