result: return nullopt if error is actuall nullptr
authorMarcus Fritzsch <marcus_fritzsch@mentor.com>
Fri, 28 Jul 2017 13:05:53 +0000 (15:05 +0200)
committerMarcus Fritzsch <marcus_fritzsch@mentor.com>
Tue, 8 Aug 2017 15:24:00 +0000 (17:24 +0200)
Signed-off-by: Marcus Fritzsch <marcus_fritzsch@mentor.com>
src/result.hpp

index b740a0c..5701f24 100644 (file)
@@ -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<T> ok() const { return this->t; }
-   optional<char const *> err() const { return optional<char const *>(this->e); }
+   optional<T> const &ok() const { return this->t; }
+   optional<char const *> err() const {
+      return this->e ? optional<char const *>(this->e) : nullopt;
+   }
 
    result<T> map_err(std::function<char const *(char const *)> f);
 };