From: Marcus Fritzsch Date: Tue, 25 Jul 2017 11:02:24 +0000 (+0200) Subject: result: implicit unwrap on conversion to result T X-Git-Tag: 4.99.1~237 X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=commitdiff_plain;h=5463a34f0136555cee0bfad9a1cb85e93aeb635c;p=staging%2Fwindowmanager.git result: implicit unwrap on conversion to result T Signed-off-by: Marcus Fritzsch --- diff --git a/src/result.hpp b/src/result.hpp index 377d5a2..e22fde9 100644 --- a/src/result.hpp +++ b/src/result.hpp @@ -22,7 +22,16 @@ struct result { bool is_ok() const { return this->t != nullopt; } bool is_err() const { return this->e != nullptr; } - T unwrap() { return this->t.value(); } + T unwrap() { + if (this->e != nullptr) { + throw std::logic_error(this->e); + } + return this->t.value(); + } + + operator T() { + return this->unwrap(); + } char const *unwrap_err() { return this->e; } };