Code Review
/
staging
/
windowmanager.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
review
|
tree
raw
|
patch
| inline |
side by side
(parent:
353bfe5
)
result: implicit unwrap on conversion to result T
author
Marcus Fritzsch
<marcus_fritzsch@mentor.com>
Tue, 25 Jul 2017 11:02:24 +0000
(13:02 +0200)
committer
Marcus Fritzsch
<marcus_fritzsch@mentor.com>
Tue, 8 Aug 2017 15:24:00 +0000
(17:24 +0200)
Signed-off-by: Marcus Fritzsch <marcus_fritzsch@mentor.com>
src/result.hpp
patch
|
blob
|
history
diff --git
a/src/result.hpp
b/src/result.hpp
index
377d5a2
..
e22fde9
100644
(file)
--- 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; }
};