From 6a27a2a4032e88fa9154ef0f0741edc584f7a701 Mon Sep 17 00:00:00 2001 From: Dominick Allen Date: Sun, 20 Oct 2024 10:48:19 -0500 Subject: Lots of work. --- include/fud_result.hpp | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) (limited to 'include/fud_result.hpp') diff --git a/include/fud_result.hpp b/include/fud_result.hpp index 4bfb819..877c49c 100644 --- a/include/fud_result.hpp +++ b/include/fud_result.hpp @@ -19,6 +19,7 @@ #define FUD_RESULT_HPP #include +#include namespace fud { @@ -28,62 +29,62 @@ class [[nodiscard]] Result { public: using ResultType = Result; - Result(const T& value) : m_value{value} + constexpr Result(const T& value) : m_value{value} { } - Result(const E& value) : m_value{value} + constexpr Result(const E& value) : m_value{value} { } - Result(T&& value) : m_value{std::move(value)} + constexpr Result(T&& value) : m_value{std::move(value)} { } - Result(E&& value) : m_value{std::move(value)} + constexpr Result(E&& value) : m_value{std::move(value)} { } - static ResultType okay(const T& okay) + static constexpr ResultType okay(const T& okay) { return ResultType{okay}; } - static ResultType okay(T&& okay) + static constexpr ResultType okay(T&& okay) { return ResultType{std::move(okay)}; } - static ResultType error(const E& error) + static constexpr ResultType error(const E& error) { return ResultType{error}; } - static ResultType error(E&& error) + static constexpr ResultType error(E&& error) { return ResultType{std::move(error)}; } template - static ResultType okay(const Result& okayRes) + static constexpr ResultType okay(const Result& okayRes) { return ResultType{okayRes.getOkay()}; } template - static ResultType okay(Result&& okayRes) + static constexpr ResultType okay(Result&& okayRes) { return ResultType{okayRes.takeOkay()}; } template - static ResultType error(const Result& errorRes) + static constexpr ResultType error(const Result& errorRes) { return ResultType{errorRes.getError()}; } template - static ResultType error(Result&& errorRes) + static constexpr ResultType error(Result&& errorRes) { return ResultType{errorRes.takeError()}; } @@ -98,28 +99,28 @@ class [[nodiscard]] Result { return (m_value.index() == 1); } - [[nodiscard]] const T& getOkay() const& + [[nodiscard]] constexpr const T& getOkay() const& { return std::get(m_value); } - [[nodiscard]] const E& getError() const& + [[nodiscard]] constexpr const E& getError() const& { return std::get(m_value); } - [[nodiscard]] T&& takeOkay() + [[nodiscard]] constexpr T&& takeOkay() { return std::move(std::get(m_value)); } - [[nodiscard]] E&& takeError() + [[nodiscard]] constexpr E&& takeError() { return std::move(std::get(m_value)); } private: - Result() : m_value() + constexpr Result() : m_value() { } -- cgit v1.2.3