mirror of
https://github.com/yuzu-emu/yuzu.git
synced 2024-11-30 10:24:20 +01:00
ResultVal: Add more convenience utils for creating and cascading results
This commit is contained in:
parent
e626a520ca
commit
7e5dd46cf4
@ -415,6 +415,16 @@ ResultVal<T> MakeResult(Args&&... args) {
|
|||||||
return ResultVal<T>::WithCode(RESULT_SUCCESS, std::forward<Args>(args)...);
|
return ResultVal<T>::WithCode(RESULT_SUCCESS, std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deducible overload of MakeResult, allowing the template parameter to be ommited if you're just
|
||||||
|
* copy or move constructing.
|
||||||
|
*/
|
||||||
|
template <typename Arg>
|
||||||
|
ResultVal<std::remove_reference_t<Arg>> MakeResult(Arg&& arg) {
|
||||||
|
return ResultVal<std::remove_reference_t<Arg>>::WithCode(RESULT_SUCCESS,
|
||||||
|
std::forward<Arg>(arg));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check for the success of `source` (which must evaluate to a ResultVal). If it succeeds, unwraps
|
* Check for the success of `source` (which must evaluate to a ResultVal). If it succeeds, unwraps
|
||||||
* the contained value and assigns it to `target`, which can be either an l-value expression or a
|
* the contained value and assigns it to `target`, which can be either an l-value expression or a
|
||||||
@ -426,3 +436,12 @@ ResultVal<T> MakeResult(Args&&... args) {
|
|||||||
if (CONCAT2(check_result_L, __LINE__).Failed()) \
|
if (CONCAT2(check_result_L, __LINE__).Failed()) \
|
||||||
return CONCAT2(check_result_L, __LINE__).Code(); \
|
return CONCAT2(check_result_L, __LINE__).Code(); \
|
||||||
target = std::move(*CONCAT2(check_result_L, __LINE__))
|
target = std::move(*CONCAT2(check_result_L, __LINE__))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Analogous to CASCADE_RESULT, but for a bare ResultCode. The code will be propagated if
|
||||||
|
* non-success, or discarded otherwise.
|
||||||
|
*/
|
||||||
|
#define CASCADE_CODE(source) \
|
||||||
|
auto CONCAT2(check_result_L, __LINE__) = source; \
|
||||||
|
if (CONCAT2(check_result_L, __LINE__).IsError()) \
|
||||||
|
return CONCAT2(check_result_L, __LINE__);
|
||||||
|
Loading…
Reference in New Issue
Block a user