X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fresult.hpp;h=e14f92b253b726b6a14fa3727de4855aaeff9a6b;hb=2b84aa5d33611d0f2f7b8c4395dc352ebf60ea29;hp=4768d9f1e30d4b3d17b7517dd856afc98c316c5b;hpb=f618aa82d6c5dbfc815b4f5f79c75325c9ee7544;p=staging%2Fwindowmanager.git diff --git a/src/result.hpp b/src/result.hpp index 4768d9f..e14f92b 100644 --- a/src/result.hpp +++ b/src/result.hpp @@ -1,6 +1,18 @@ -// -// Created by mfritzsc on 7/12/17. -// +/* + * Copyright (C) 2017 Mentor Graphics Development (Deutschland) GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ #ifndef TMCAGLWM_RESULT_HPP #define TMCAGLWM_RESULT_HPP @@ -30,17 +42,14 @@ struct result { return this->t.value(); } - operator T() { - return this->unwrap(); - } + operator T() { return this->unwrap(); } char const *unwrap_err() { return this->e; } - optional ok() const { return this->t; } - optional err() const { return optional(this->e); } - - template - result map(std::function f); + optional const &ok() const { return this->t; } + optional err() const { + return this->e ? optional(this->e) : nullopt; + } result map_err(std::function f); }; @@ -55,15 +64,6 @@ struct result Ok(T t) { return result{nullptr, t}; } -template -template -result result::map(std::function f) { - if (this->is_ok()) { - return Ok(f(this->unwrap())); - } - return Err(this->e); -} - template result result::map_err(std::function f) { if (this->is_err()) {