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; }
26 if (this->e != nullptr) {
27 throw std::logic_error(this->e);
29 return this->t.value();
33 return this->unwrap();
36 char const *unwrap_err() { return this->e; }
40 struct result<T> Err(char const *e) {
41 return result<T>{e, nullopt};
45 struct result<T> Ok(T t) {
46 return result<T>{nullptr, t};
51 #endif // TMCAGLWM_RESULT_HPP