From 2357c437b260d0d8cb927e6878f1226bfafb9d0b Mon Sep 17 00:00:00 2001 From: Kazumasa Mitsunari Date: Wed, 30 May 2018 17:33:48 +0900 Subject: Format source codes * Format source codes * Change indent spaces to 4 from 3 * Remove trailing spaces in config.xml Change-Id: I745ba6c7cc4dcf4177add81666351c3c01de7d44 Signed-off-by: Kazumasa Mitsunari --- src/result.hpp | 83 ++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 46 insertions(+), 37 deletions(-) (limited to 'src/result.hpp') diff --git a/src/result.hpp b/src/result.hpp index 09eadb5..8a59a90 100644 --- a/src/result.hpp +++ b/src/result.hpp @@ -20,58 +20,67 @@ #include #include -namespace wm { +namespace wm +{ -using std::experimental::optional; using std::experimental::nullopt; +using std::experimental::optional; // 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() { - if (this->e != nullptr) { - throw std::logic_error(this->e); - } - return this->t.value(); - } - - operator T() { return this->unwrap(); } - - char const *unwrap_err() { return this->e; } - - optional const &ok() const { return this->t; } - optional err() const { - return this->e ? optional(this->e) : nullopt; - } - - result map_err(std::function f); +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() + { + if (this->e != nullptr) + { + throw std::logic_error(this->e); + } + return this->t.value(); + } + + operator T() { return this->unwrap(); } + + char const *unwrap_err() { return this->e; } + + optional const &ok() const { return this->t; } + optional err() const + { + return this->e ? optional(this->e) : nullopt; + } + + result map_err(std::function f); }; template -struct result Err(char const *e) { - return result{e, nullopt}; +struct result Err(char const *e) +{ + return result{e, nullopt}; } template -struct result Ok(T t) { - return result{nullptr, t}; +struct result Ok(T t) +{ + return result{nullptr, t}; } template -result result::map_err(std::function f) { - if (this->is_err()) { - return Err(f(this->e)); - } - return *this; +result result::map_err(std::function f) +{ + if (this->is_err()) + { + return Err(f(this->e)); + } + return *this; } -} // namespace wm +} // namespace wm -#endif // TMCAGLWM_RESULT_HPP +#endif // TMCAGLWM_RESULT_HPP -- cgit 1.2.3-korg