diff options
author | 2017-07-25 13:02:24 +0200 | |
---|---|---|
committer | 2017-08-08 17:24:00 +0200 | |
commit | 5463a34f0136555cee0bfad9a1cb85e93aeb635c (patch) | |
tree | 94cd8b0ac95513ef9a025ba054ecb15ba46e5861 | |
parent | 353bfe55c134bb19247bf26c2498c0d87f80dc18 (diff) |
result: implicit unwrap on conversion to result T
Signed-off-by: Marcus Fritzsch <marcus_fritzsch@mentor.com>
-rw-r--r-- | src/result.hpp | 11 |
1 files changed, 10 insertions, 1 deletions
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; } }; |