1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 17:27:35 +00:00

AK: Enable direct comparsion of Optional<T> and T

This patch introduces a new operator== to compare an Optional to its
contained type directly. If the Optional does not contain a value, the
comparison will always return false.

This also adds a test case for the new behavior as well as comparison
between Optional objects themselves.
This commit is contained in:
Max Wipfli 2021-06-01 10:12:53 +02:00 committed by Andreas Kling
parent 12a42edd13
commit f3fda59abd
2 changed files with 49 additions and 0 deletions

View file

@ -100,6 +100,12 @@ public:
return has_value() == other.has_value() && (!has_value() || value() == other.value());
}
template<typename O>
ALWAYS_INLINE bool operator==(O const& other) const
{
return has_value() && value() == other;
}
ALWAYS_INLINE ~Optional()
{
clear();