Skip to content

Commit 3dd5c8e

Browse files
committed
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 <harald.fernengel@here.com>
1 parent 5425332 commit 3dd5c8e

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

olp-cpp-sdk-core/include/olp/core/client/CancellationContext.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ class CORE_API CancellationContext {
8383
private:
8484
/// A helper for unordered containers.
8585
friend struct CancellationContextHash;
86+
friend struct CancellationContextEquality;
8687

8788
/**
8889
* @brief An implementation used to shared the `CancellationContext` instance.
@@ -126,6 +127,22 @@ struct CORE_API CancellationContextHash {
126127
size_t operator()(const CancellationContext& context) const;
127128
};
128129

130+
/**
131+
* @brief A helper for unordered containers for equality comparison
132+
*/
133+
struct CORE_API CancellationContextEquality {
134+
/**
135+
* @brief Checks equality for two `CancellationContext` instances.
136+
*
137+
* @param lhs The first `CancellationContext` instance.
138+
* @param rhs The second `CancellationContext` instance.
139+
*
140+
* @return True if both refer to the same implementation; false otherwise.
141+
*/
142+
bool operator()(const CancellationContext& lhs,
143+
const CancellationContext& rhs) const;
144+
};
145+
129146
} // namespace client
130147
} // namespace olp
131148

olp-cpp-sdk-core/include/olp/core/client/CancellationContext.inl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,11 @@ inline size_t CancellationContextHash::operator()(
7979
context.impl_);
8080
}
8181

82+
bool CancellationContextEquality::operator()(
83+
const olp::client::CancellationContext& lhs,
84+
const olp::client::CancellationContext& rhs) const {
85+
return lhs.impl_ == rhs.impl_;
86+
}
87+
8288
} // namespace client
8389
} // namespace olp

0 commit comments

Comments
 (0)