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.hpp55
1 files changed, 34 insertions, 21 deletions
diff --git a/include/fud_result.hpp b/include/fud_result.hpp
index 5dabaf5..4bfb819 100644
--- a/include/fud_result.hpp
+++ b/include/fud_result.hpp
@@ -28,6 +28,22 @@ class [[nodiscard]] Result {
public:
using ResultType = Result<T, E>;
+ Result(const T& value) : m_value{value}
+ {
+ }
+
+ Result(const E& value) : m_value{value}
+ {
+ }
+
+ Result(T&& value) : m_value{std::move(value)}
+ {
+ }
+
+ Result(E&& value) : m_value{std::move(value)}
+ {
+ }
+
static ResultType okay(const T& okay)
{
return ResultType{okay};
@@ -49,22 +65,26 @@ class [[nodiscard]] Result {
}
template <typename F>
- static ResultType okay(const Result<T, F>& okayRes) {
+ static ResultType okay(const Result<T, F>& okayRes)
+ {
return ResultType{okayRes.getOkay()};
}
template <typename F>
- static ResultType okay(Result<T, F>&& okayRes) {
+ static ResultType okay(Result<T, F>&& okayRes)
+ {
return ResultType{okayRes.takeOkay()};
}
template <typename U>
- static ResultType error(const Result<U, E>& errorRes) {
+ static ResultType error(const Result<U, E>& errorRes)
+ {
return ResultType{errorRes.getError()};
}
template <typename U>
- static ResultType error(Result<U, E>&& errorRes) {
+ static ResultType error(Result<U, E>&& errorRes)
+ {
return ResultType{errorRes.takeError()};
}
@@ -99,29 +119,22 @@ class [[nodiscard]] Result {
}
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)}
+ Result() : m_value()
{
}
std::variant<T, E> m_value;
};
+#define M_TakeOrReturn(HYGIENE_EXPRESSION) \
+ ({ \
+ auto HYGIENE_RESULT{(HYGIENE_EXPRESSION)}; \
+ if (HYGIENE_RESULT.isError()) { \
+ return HYGIENE_RESULT.takeError(); \
+ } \
+ HYGIENE_RESULT.takeOkay(); \
+ })
+
} // namespace fud
#endif