diff options
| author | 2021-11-01 10:38:11 -0400 | |
|---|---|---|
| committer | 2021-11-02 15:20:36 -0400 | |
| commit | 98b351758c9912735ad0cedd0ab68c39185e6040 (patch) | |
| tree | 8bdb8a761e44841d8a94c27b77d6b630517caa83 /src | |
| parent | hle/result: Reimplement ResultVal using Common::Expected (diff) | |
| download | yuzu-98b351758c9912735ad0cedd0ab68c39185e6040.tar.gz yuzu-98b351758c9912735ad0cedd0ab68c39185e6040.tar.xz yuzu-98b351758c9912735ad0cedd0ab68c39185e6040.zip | |
hle/result: Amend ResultVal documentation
This amends the documentation slightly to reflect the updated interface.
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/hle/result.h | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/src/core/hle/result.h b/src/core/hle/result.h index 29fa4eed2..a1917d32b 100644 --- a/src/core/hle/result.h +++ b/src/core/hle/result.h | |||
| @@ -154,34 +154,32 @@ constexpr ResultCode ResultSuccess(0); | |||
| 154 | constexpr ResultCode ResultUnknown(UINT32_MAX); | 154 | constexpr ResultCode ResultUnknown(UINT32_MAX); |
| 155 | 155 | ||
| 156 | /** | 156 | /** |
| 157 | * This is an optional value type. It holds a `ResultCode` and, if that code is a success code, | 157 | * This is an optional value type. It holds a `ResultCode` and, if that code is ResultSuccess, it |
| 158 | * also holds a result of type `T`. If the code is an error code then trying to access the inner | 158 | * also holds a result of type `T`. If the code is an error code (not ResultSuccess), then trying |
| 159 | * value fails, thus ensuring that the ResultCode of functions is always checked properly before | 159 | * to access the inner value with operator* is undefined behavior and will assert with Unwrap(). |
| 160 | * their return value is used. It is similar in concept to the `std::optional` type | 160 | * Users of this class must be cognizant to check the status of the ResultVal with operator bool(), |
| 161 | * (http://en.cppreference.com/w/cpp/experimental/optional) originally proposed for inclusion in | 161 | * Code(), Succeeded() or Failed() prior to accessing the inner value. |
| 162 | * C++14, or the `Result` type in Rust (http://doc.rust-lang.org/std/result/index.html). | ||
| 163 | * | 162 | * |
| 164 | * An example of how it could be used: | 163 | * An example of how it could be used: |
| 165 | * \code | 164 | * \code |
| 166 | * ResultVal<int> Frobnicate(float strength) { | 165 | * ResultVal<int> Frobnicate(float strength) { |
| 167 | * if (strength < 0.f || strength > 1.0f) { | 166 | * if (strength < 0.f || strength > 1.0f) { |
| 168 | * // Can't frobnicate too weakly or too strongly | 167 | * // Can't frobnicate too weakly or too strongly |
| 169 | * return ResultCode(ErrorDescription::OutOfRange, ErrorModule::Common, | 168 | * return ResultCode{ErrorModule::Common, 1}; |
| 170 | * ErrorSummary::InvalidArgument, ErrorLevel::Permanent); | ||
| 171 | * } else { | 169 | * } else { |
| 172 | * // Frobnicated! Give caller a cookie | 170 | * // Frobnicated! Give caller a cookie |
| 173 | * return MakeResult<int>(42); | 171 | * return MakeResult(42); |
| 174 | * } | 172 | * } |
| 175 | * } | 173 | * } |
| 176 | * \endcode | 174 | * \endcode |
| 177 | * | 175 | * |
| 178 | * \code | 176 | * \code |
| 179 | * ResultVal<int> frob_result = Frobnicate(0.75f); | 177 | * auto frob_result = Frobnicate(0.75f); |
| 180 | * if (frob_result) { | 178 | * if (frob_result) { |
| 181 | * // Frobbed ok | 179 | * // Frobbed ok |
| 182 | * printf("My cookie is %d\n", *frob_result); | 180 | * printf("My cookie is %d\n", *frob_result); |
| 183 | * } else { | 181 | * } else { |
| 184 | * printf("Guess I overdid it. :( Error code: %ux\n", frob_result.code().hex); | 182 | * printf("Guess I overdid it. :( Error code: %ux\n", frob_result.Code().raw); |
| 185 | * } | 183 | * } |
| 186 | * \endcode | 184 | * \endcode |
| 187 | */ | 185 | */ |
| @@ -283,7 +281,7 @@ private: | |||
| 283 | 281 | ||
| 284 | /** | 282 | /** |
| 285 | * This function is a helper used to construct `ResultVal`s. It receives the arguments to construct | 283 | * This function is a helper used to construct `ResultVal`s. It receives the arguments to construct |
| 286 | * `T` with and creates a success `ResultVal` contained the constructed value. | 284 | * `T` with and creates a `ResultVal` that contains the constructed value. |
| 287 | */ | 285 | */ |
| 288 | template <typename T, typename... Args> | 286 | template <typename T, typename... Args> |
| 289 | [[nodiscard]] ResultVal<T> MakeResult(Args&&... args) { | 287 | [[nodiscard]] ResultVal<T> MakeResult(Args&&... args) { |