2 // Created by mfritzsc on 7/12/17.
5 #ifndef TMCAGLWM_RESULT_HPP
6 #define TMCAGLWM_RESULT_HPP
8 #include <experimental/optional>
12 using std::experimental::optional;
13 using std::experimental::nullopt;
15 // We only ever return a string as an error - so just parametrize
16 // this over result type T
22 bool is_ok() const { return this->t != nullopt; }
23 bool is_err() const { return this->e != nullptr; }
25 T unwrap() { return this->t.value(); }
27 char const *unwrap_err() { return this->e; }
31 struct result<T> Err(char const *e) {
32 return result<T>{e, nullopt};
36 struct result<T> Ok(T t) {
37 return result<T>{nullptr, t};
42 #endif // TMCAGLWM_RESULT_HPP