3
0
Fork 0
forked from suyu/suyu

hle/result: Amend ResultVal documentation

This amends the documentation slightly to reflect the updated interface.
This commit is contained in:
Morph 2021-11-01 10:38:11 -04:00
parent 52e52924bb
commit 98b351758c

View file

@ -154,34 +154,32 @@ constexpr ResultCode ResultSuccess(0);
constexpr ResultCode ResultUnknown(UINT32_MAX); constexpr ResultCode ResultUnknown(UINT32_MAX);
/** /**
* This is an optional value type. It holds a `ResultCode` and, if that code is a success code, * This is an optional value type. It holds a `ResultCode` and, if that code is ResultSuccess, it
* also holds a result of type `T`. If the code is an error code then trying to access the inner * also holds a result of type `T`. If the code is an error code (not ResultSuccess), then trying
* value fails, thus ensuring that the ResultCode of functions is always checked properly before * to access the inner value with operator* is undefined behavior and will assert with Unwrap().
* their return value is used. It is similar in concept to the `std::optional` type * Users of this class must be cognizant to check the status of the ResultVal with operator bool(),
* (http://en.cppreference.com/w/cpp/experimental/optional) originally proposed for inclusion in * Code(), Succeeded() or Failed() prior to accessing the inner value.
* C++14, or the `Result` type in Rust (http://doc.rust-lang.org/std/result/index.html).
* *
* An example of how it could be used: * An example of how it could be used:
* \code * \code
* ResultVal<int> Frobnicate(float strength) { * ResultVal<int> Frobnicate(float strength) {
* if (strength < 0.f || strength > 1.0f) { * if (strength < 0.f || strength > 1.0f) {
* // Can't frobnicate too weakly or too strongly * // Can't frobnicate too weakly or too strongly
* return ResultCode(ErrorDescription::OutOfRange, ErrorModule::Common, * return ResultCode{ErrorModule::Common, 1};
* ErrorSummary::InvalidArgument, ErrorLevel::Permanent);
* } else { * } else {
* // Frobnicated! Give caller a cookie * // Frobnicated! Give caller a cookie
* return MakeResult<int>(42); * return MakeResult(42);
* } * }
* } * }
* \endcode * \endcode
* *
* \code * \code
* ResultVal<int> frob_result = Frobnicate(0.75f); * auto frob_result = Frobnicate(0.75f);
* if (frob_result) { * if (frob_result) {
* // Frobbed ok * // Frobbed ok
* printf("My cookie is %d\n", *frob_result); * printf("My cookie is %d\n", *frob_result);
* } else { * } else {
* printf("Guess I overdid it. :( Error code: %ux\n", frob_result.code().hex); * printf("Guess I overdid it. :( Error code: %ux\n", frob_result.Code().raw);
* } * }
* \endcode * \endcode
*/ */
@ -283,7 +281,7 @@ private:
/** /**
* This function is a helper used to construct `ResultVal`s. It receives the arguments to construct * This function is a helper used to construct `ResultVal`s. It receives the arguments to construct
* `T` with and creates a success `ResultVal` contained the constructed value. * `T` with and creates a `ResultVal` that contains the constructed value.
*/ */
template <typename T, typename... Args> template <typename T, typename... Args>
[[nodiscard]] ResultVal<T> MakeResult(Args&&... args) { [[nodiscard]] ResultVal<T> MakeResult(Args&&... args) {