From 7e5dd46cf4c7be421b6a86a661f6dd9cd1ef4332 Mon Sep 17 00:00:00 2001 From: Yuri Kunde Schlesner Date: Mon, 5 Jun 2017 23:13:58 -0700 Subject: ResultVal: Add more convenience utils for creating and cascading results --- src/core/hle/result.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src') diff --git a/src/core/hle/result.h b/src/core/hle/result.h index c49650f7d..5f2cdbb96 100644 --- a/src/core/hle/result.h +++ b/src/core/hle/result.h @@ -415,6 +415,16 @@ ResultVal MakeResult(Args&&... args) { return ResultVal::WithCode(RESULT_SUCCESS, std::forward(args)...); } +/** + * Deducible overload of MakeResult, allowing the template parameter to be ommited if you're just + * copy or move constructing. + */ +template +ResultVal> MakeResult(Arg&& arg) { + return ResultVal>::WithCode(RESULT_SUCCESS, + std::forward(arg)); +} + /** * 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 @@ -426,3 +436,12 @@ ResultVal MakeResult(Args&&... args) { if (CONCAT2(check_result_L, __LINE__).Failed()) \ return CONCAT2(check_result_L, __LINE__).Code(); \ 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__); -- cgit v1.2.3