From bd3363946030c35ed5b795d5b30d5d2a34aaad84 Mon Sep 17 00:00:00 2001 From: Marcus Fritzsch Date: Fri, 28 Jul 2017 15:05:53 +0200 Subject: [PATCH] result: return nullopt if error is actuall nullptr Signed-off-by: Marcus Fritzsch --- src/result.hpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/result.hpp b/src/result.hpp index b740a0c..5701f24 100644 --- a/src/result.hpp +++ b/src/result.hpp @@ -30,14 +30,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); } + optional const &ok() const { return this->t; } + optional err() const { + return this->e ? optional(this->e) : nullopt; + } result map_err(std::function f); }; -- 2.16.6