summaryrefslogtreecommitdiffstats
path: root/src/result.hpp
diff options
context:
space:
mode:
authorMarcus Fritzsch <marcus_fritzsch@mentor.com>2017-07-12 15:59:37 +0200
committerMarcus Fritzsch <marcus_fritzsch@mentor.com>2017-08-08 17:24:00 +0200
commit54c34361d08386c751897ee215554c9ea1efd108 (patch)
tree28ae052b7e819d9f5308b3545beb029c88a476d7 /src/result.hpp
parent628df48e0238391658dab54f81dfa1c62dbfb3ec (diff)
Generating binding API glue code using generate-binding.py
Signed-off-by: Marcus Fritzsch <marcus_fritzsch@mentor.com>
Diffstat (limited to 'src/result.hpp')
-rw-r--r--src/result.hpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/result.hpp b/src/result.hpp
new file mode 100644
index 0000000..fe9956b
--- /dev/null
+++ b/src/result.hpp
@@ -0,0 +1,38 @@
+//
+// Created by mfritzsc on 7/12/17.
+//
+
+#ifndef TMCAGLWM_RESULT_HPP
+#define TMCAGLWM_RESULT_HPP
+
+#include <experimental/optional>
+
+namespace wm {
+
+ using std::experimental::optional;
+ using std::experimental::nullopt;
+
+ // We only ever return a string as an error - so just parametrize
+ // this over result type T
+ template<typename T>
+ struct result {
+ char const *e;
+ optional<T> t;
+
+ bool is_ok() const { return this->t != nullopt; }
+ bool is_err() const { return this->e != nullptr; }
+
+ T unwrap() { return this->t.value(); }
+
+ char const *unwrap_err() { return this->e; }
+ };
+
+ template<typename T>
+ struct result<T> Err(char const *e) { return result<T>{e, nullopt}; }
+
+ template<typename T>
+ struct result<T> Ok(T t) { return result<T>{nullptr, t}; }
+
+} // namespace wm
+
+#endif //TMCAGLWM_RESULT_HPP