Skip to content

Commit e043656

Browse files
authored
Merge pull request #1886 from ApexAI/iox-1884-optional-inequality-operator-fix
iox-#1884 Use inequality operator of underlying type in optional ineq…
2 parents 45371d8 + 2a33654 commit e043656

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)