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