Skip to content

Commit f3f0e16

Browse files
fix: Add constraint clauses and optimize error prompts
1 parent c701e23 commit f3f0e16

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

src/policy/impl.cppm

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,20 @@ template <typename T> constexpr void assert_atomic_ref_compatible() {
158158
"satisfy std::atomic_ref<CommonRep>::required_alignment");
159159
}
160160

161+
template <typename T>
162+
concept has_underlying_rep_not_equal =
163+
underlying_type<T> &&
164+
requires(T const &lhs, T const &rhs) {
165+
{
166+
underlying::traits<std::remove_cv_t<T>>::to_rep(lhs) !=
167+
underlying::traits<std::remove_cv_t<T>>::to_rep(rhs)
168+
} -> std::convertible_to<bool>;
169+
};
170+
171+
template <typename T>
172+
inline constexpr bool none_compare_exchange_available_v =
173+
has_underlying_rep_not_equal<T>;
174+
161175
template <typename OpTag>
162176
inline constexpr bool is_arithmetic_operation_v =
163177
operations::op_has_capability_v<OpTag, operations::capability::arithmetic>;
@@ -255,8 +269,10 @@ struct concurrency::handler<concurrency::none, void, CommonRep, ErrorPayload> {
255269
}
256270

257271
static constexpr auto compare_exchange(CommonRep &value, CommonRep &expected,
258-
CommonRep desired) noexcept -> bool {
259-
if (value != expected) {
272+
CommonRep desired) noexcept -> bool
273+
requires(details::none_compare_exchange_available_v<CommonRep>) {
274+
using traits_type = underlying::traits<std::remove_cv_t<CommonRep>>;
275+
if (traits_type::to_rep(value) != traits_type::to_rep(expected)) {
260276
expected = value;
261277
return false;
262278
}

0 commit comments

Comments
 (0)