base: add == operator to util/attempt.h

This simplifies testing for early return conditions for which the use of
lambdas would be quite noisy.

genodelabs/genode#4393
This commit is contained in:
Johannes Schlatow 2022-02-01 15:03:47 +01:00 committed by Norman Feske
parent 024b987e4c
commit b821776b0d

View File

@ -72,6 +72,12 @@ class Genode::Attempt
fail_fn(_error); fail_fn(_error);
} }
bool operator == (ERROR const &rhs) const {
return failed() && (_error == rhs); }
bool operator == (RESULT const &rhs) const {
return ok() && (_result == rhs); }
bool ok() const { return _ok; } bool ok() const { return _ok; }
bool failed() const { return !_ok; } bool failed() const { return !_ok; }
}; };