Skip to content

Commit

Permalink
Add operator != for optional type
Browse files Browse the repository at this point in the history
  • Loading branch information
mhekkel committed Jun 12, 2024
1 parent cefeebb commit 6c32a9f
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions include/cif++/condition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1284,6 +1284,19 @@ condition operator==(const key &key, const std::optional<T> &v)
return condition(new detail::key_is_empty_condition_impl(key.m_item_name));
}

/**
* @brief Create a condition to search any item for a value @a v if @a v contains a value
* compare to null if not.
*/
template <typename T>
condition operator!=(const key &key, const std::optional<T> &v)
{
if (v.has_value())
return condition(new detail::not_condition_impl({new detail::key_equals_condition_impl({ key.m_item_name, *v })}));
else
return condition(new detail::not_condition_impl({new detail::key_is_empty_condition_impl(key.m_item_name)}));
}

/**
* @brief Operator to create a boolean opposite of the condition in @a rhs
*/
Expand Down

0 comments on commit 6c32a9f

Please sign in to comment.