diff options
Diffstat (limited to 'include/fud_result.hpp')
-rw-r--r-- | include/fud_result.hpp | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/include/fud_result.hpp b/include/fud_result.hpp index e4e36cf..9b96399 100644 --- a/include/fud_result.hpp +++ b/include/fud_result.hpp @@ -23,9 +23,10 @@ namespace fud { -template<typename T, typename E> +/** \brief A result type which contains either a T on success or an E on error. */ +template <typename T, typename E> class [[nodiscard]] Result { -public: + public: using ResultType = Result<T, E>; static ResultType okay(const T& okay) { @@ -49,12 +50,12 @@ public: [[nodiscard]] constexpr bool isOkay() const { - return(m_value.index() == 0); + return (m_value.index() == 0); } [[nodiscard]] constexpr bool isError() const { - return(m_value.index() == 1); + return (m_value.index() == 1); } T getOkay() @@ -67,17 +68,27 @@ public: return std::get<E>(m_value); } -private: - explicit Result() : m_value() {} - explicit Result(const T& value) : m_value(value) {} - explicit Result(const E& value) : m_value(value) {} + private: + explicit Result() : m_value() + { + } + explicit Result(const T& value) : m_value(value) + { + } + explicit Result(const E& value) : m_value(value) + { + } - explicit Result(T&& value) : m_value(std::move(value)) {} - explicit Result(E&& value) : m_value(std::move(value)) {} + explicit Result(T&& value) : m_value(std::move(value)) + { + } + explicit Result(E&& value) : m_value(std::move(value)) + { + } std::variant<T, E> m_value; }; -} // namespace bookmouse +} // namespace fud #endif |