mirror of
https://github.com/arcan1s/result.git
synced 2025-07-02 00:15:52 +00:00
move Result::match inside class
This commit is contained in:
37
result.hpp
37
result.hpp
@ -164,6 +164,32 @@ public:
|
|||||||
return Content::Empty;
|
return Content::Empty;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
/**
|
||||||
|
* @brief match result function
|
||||||
|
* @tparam UnaryFunctionValue
|
||||||
|
* function type which will be called if result contains value
|
||||||
|
* @tparam UnaryFunctionError
|
||||||
|
* function type which will be called if result contains error
|
||||||
|
* @param apply_value
|
||||||
|
* function which will be called if result contains value
|
||||||
|
* @param apply_error
|
||||||
|
* function which will be called if result contains error
|
||||||
|
*/
|
||||||
|
template <typename UnaryFunctionValue, typename UnaryFunctionError>
|
||||||
|
void match(UnaryFunctionValue apply_value,
|
||||||
|
UnaryFunctionError apply_error) const
|
||||||
|
{
|
||||||
|
switch (type()) {
|
||||||
|
case Content::Value:
|
||||||
|
apply_value(get());
|
||||||
|
break;
|
||||||
|
case Content::Error:
|
||||||
|
apply_error(error());
|
||||||
|
break;
|
||||||
|
case Content::Empty:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
// additional functions
|
// additional functions
|
||||||
@ -189,16 +215,7 @@ template <typename T, typename ErrorEnum, typename UnaryFunctionValue,
|
|||||||
void match(const Result<T, ErrorEnum> &result, UnaryFunctionValue apply_value,
|
void match(const Result<T, ErrorEnum> &result, UnaryFunctionValue apply_value,
|
||||||
UnaryFunctionError apply_error)
|
UnaryFunctionError apply_error)
|
||||||
{
|
{
|
||||||
switch (result.type()) {
|
return result.match(apply_value, apply_error);
|
||||||
case Content::Value:
|
|
||||||
apply_value(result.get());
|
|
||||||
break;
|
|
||||||
case Content::Error:
|
|
||||||
apply_error(result.error());
|
|
||||||
break;
|
|
||||||
case Content::Empty:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user