Skip to content

Commit 7dff5ea

Browse files
authored
Allow CancellationContext in hashes (#1612)
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 7dff5ea

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,10 @@ inline size_t CancellationContextHash::operator()(
7979
context.impl_);
8080
}
8181

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

0 commit comments

Comments
 (0)