summaryrefslogtreecommitdiff
path: root/include/fud_result.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'include/fud_result.hpp')
-rw-r--r--include/fud_result.hpp35
1 files changed, 18 insertions, 17 deletions
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 <variant>
+#include <utility>
namespace fud {
@@ -28,62 +29,62 @@ class [[nodiscard]] Result {
public:
using ResultType = Result<T, E>;
- 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 <typename F>
- static ResultType okay(const Result<T, F>& okayRes)
+ static constexpr ResultType okay(const Result<T, F>& okayRes)
{
return ResultType{okayRes.getOkay()};
}
template <typename F>
- static ResultType okay(Result<T, F>&& okayRes)
+ static constexpr ResultType okay(Result<T, F>&& okayRes)
{
return ResultType{okayRes.takeOkay()};
}
template <typename U>
- static ResultType error(const Result<U, E>& errorRes)
+ static constexpr ResultType error(const Result<U, E>& errorRes)
{
return ResultType{errorRes.getError()};
}
template <typename U>
- static ResultType error(Result<U, E>&& errorRes)
+ static constexpr ResultType error(Result<U, E>&& 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<T>(m_value);
}
- [[nodiscard]] const E& getError() const&
+ [[nodiscard]] constexpr const E& getError() const&
{
return std::get<E>(m_value);
}
- [[nodiscard]] T&& takeOkay()
+ [[nodiscard]] constexpr T&& takeOkay()
{
return std::move(std::get<T>(m_value));
}
- [[nodiscard]] E&& takeError()
+ [[nodiscard]] constexpr E&& takeError()
{
return std::move(std::get<E>(m_value));
}
private:
- Result() : m_value()
+ constexpr Result() : m_value()
{
}