Add ops == and != for Optional

This commit is contained in:
Martin Jeřábek 2021-03-08 14:43:42 +01:00 committed by Martin Hořeňovský
parent f00b6e2019
commit f0a89b7345
No known key found for this signature in database
GPG Key ID: DE48307B8B0D381A
1 changed files with 13 additions and 0 deletions

View File

@ -75,6 +75,19 @@ namespace Catch {
return some();
}
friend bool operator==(Optional const& a, Optional const& b) {
if (a.none() && b.none()) {
return true;
} else if (a.some() && b.some()) {
return *a == *b;
} else {
return false;
}
}
friend bool operator!=(Optional const& a, Optional const& b) {
return !( a == b );
}
private:
T *nullableValue;
alignas(alignof(T)) char storage[sizeof(T)];