#define TMCAGLWM_RESULT_HPP
#include <experimental/optional>
+#include <functional>
namespace wm {
}
char const *unwrap_err() { return this->e; }
+
+ optional<T> ok() const { return this->t; }
+ optional<char const *> err() const { return optional<char const *>(this->e); }
+
+ template <typename U>
+ result<U> map(std::function<U(T)> f);
+
+ result<T> map_err(std::function<char const *(char const *)> f);
};
template <typename T>
return result<T>{nullptr, t};
}
+template <typename T>
+template <typename U>
+result<U> result<T>::map(std::function<U(T)> f) {
+ if (this->is_ok()) {
+ return Ok<U>(f(this->unwrap()));
+ }
+ return Err<U>(this->e);
+}
+
+template <typename T>
+result<T> result<T>::map_err(std::function<char const *(char const *)> f) {
+ if (this->is_err()) {
+ return Err<T>(f(this->e));
+ }
+ return *this;
+}
+
} // namespace wm
#endif // TMCAGLWM_RESULT_HPP