From 51d8d16114a99aa95dd95664a4ea13a93bad69fd Mon Sep 17 00:00:00 2001 From: Teon Banek Date: Mon, 9 Sep 2019 15:07:52 +0200 Subject: [PATCH] Add utils::BasicResult specialization for `void` Reviewers: mferencevic, ipaljak Reviewed By: mferencevic Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D2365 --- src/utils/result.hpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/utils/result.hpp b/src/utils/result.hpp index 375407ece..e7316388c 100644 --- a/src/utils/result.hpp +++ b/src/utils/result.hpp @@ -93,4 +93,37 @@ class [[nodiscard]] BasicResult final { std::optional error_; }; +template +class [[nodiscard]] BasicResult final { + public: + BasicResult() = default; + BasicResult(const TError &error) : error_(error) {} + BasicResult(TError &&error) noexcept : error_(std::move(error)) {} + + bool HasError() const { return error_.has_value(); } + + TError &GetError() & { + CHECK(error_) << "The storage result is a value!"; + return *error_; + } + + TError &&GetError() && { + CHECK(error_) << "The storage result is a value!"; + return std::move(*error_); + } + + const TError &GetError() const & { + CHECK(error_) << "The storage result is a value!"; + return *error_; + } + + const TError &&GetError() const && { + CHECK(error_) << "The storage result is a value!"; + return std::move(*error_); + } + + private: + std::optional error_; +}; + } // namespace utils