mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 07:57:46 +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:
parent
12a42edd13
commit
f3fda59abd
2 changed files with 49 additions and 0 deletions
|
@ -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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue