// // Created by mfritzsc on 7/12/17. // #ifndef TMCAGLWM_RESULT_HPP #define TMCAGLWM_RESULT_HPP #include 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 struct result { char const *e; optional 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 struct result Err(char const *e) { return result{e, nullopt}; } template struct result Ok(T t) { return result{nullptr, t}; } } // namespace wm #endif //TMCAGLWM_RESULT_HPP