X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fresult.hpp;h=8a59a9014404120fbfdd2685274f20500e3fe4a3;hb=refs%2Ftags%2Fflounder%2F6.0.2;hp=e14f92b253b726b6a14fa3727de4855aaeff9a6b;hpb=074d058a7a483a66af7f8c0b928b321ad483f47c;p=apps%2Fagl-service-windowmanager-2017.git diff --git a/src/result.hpp b/src/result.hpp index e14f92b..8a59a90 100644 --- a/src/result.hpp +++ b/src/result.hpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017 Mentor Graphics Development (Deutschland) GmbH + * Copyright (c) 2017 TOYOTA MOTOR CORPORATION * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -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