Skip to content

Commit 2a33654

Browse files
committed
iox-#1884 Use inequality operator of underlying type in optional inequality implementation
Signed-off-by: Christian Eltzschig <[email protected]>
1 parent e832ccb commit 2a33654

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

iceoryx_hoofs/vocabulary/include/iox/detail/optional.inl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,10 @@ bool operator==(const optional<T>& lhs, const optional<T>& rhs) noexcept
306306
template <typename T>
307307
bool operator!=(const optional<T>& lhs, const optional<T>& rhs) noexcept
308308
{
309-
return !(lhs == rhs);
309+
const auto onlyLhsNul = !lhs.has_value() && rhs.has_value();
310+
const auto onlyRhsNul = lhs.has_value() && !rhs.has_value();
311+
const auto bothValuesUnequal = (lhs.has_value() && rhs.has_value()) && (*lhs != *rhs);
312+
return bothValuesUnequal || onlyRhsNul || onlyLhsNul;
310313
}
311314

312315
// AXIVION DISABLE STYLE AutosarC++19_03-A13.5.5: Comparison with nullopt_t is required

0 commit comments

Comments
 (0)