载入中...
搜索中...
未找到
Result.h
浏览该文件的文档.
39EVENGINE_API_FOUNDATION void checkResultInvariant(bool condition, const char* expression, const char* file,
52[[noreturn]] EVENGINE_API_FOUNDATION void failResultExpectation(const Status& status, std::string_view message,
176class [[nodiscard("Result must be checked or explicitly ignored")]] Result : private detail::ResultObservation {
177 static_assert(!std::is_reference_v<T>, "Result<T> cannot hold a reference; use a handle or value");
185 static Result success(T value) { return Result(Status::success(), std::optional<T>(std::move(value))); }
204 static Result failure(Diagnostic diagnostic) { return failure(Status::failure(std::move(diagnostic))); }
344 EV_DETAIL_RESULT_ASSERT(hasSuccessfulValue, "Result::value requires a successful Result with a value");
354 EV_DETAIL_RESULT_ASSERT(hasSuccessfulValue, "Result::value requires a successful Result with a value");
364 EV_DETAIL_RESULT_ASSERT(hasSuccessfulValue, "Result::value requires a successful Result with a value");
375 EV_DETAIL_RESULT_ASSERT(hasSuccessfulValue, "Result::takeValue requires a successful Result with a value");
462class [[nodiscard("Result must be checked or explicitly ignored")]] Result<void> : private detail::ResultObservation {
484 static Result failure(Diagnostic diagnostic) { return failure(Status::failure(std::move(diagnostic))); }
492 : detail::ResultObservation(detail::ResultObservation::InactiveTag{}), status_(std::move(other.status_)) {
564 EV_DETAIL_RESULT_ASSERT(status_.isSuccess(), "Result<void>::value requires a successful Result");
Structured operation status used by the common Result foundation.
A structured explanation of a failed, degraded, or noteworthy result.
Definition Diagnostic.h:94
const Diagnostic * error() const noexcept
Inspect the first diagnostic, or null when none was supplied.
Definition Result.h:550
bool ok() const noexcept
Whether this result represents a non-failure outcome.
Definition Result.h:514
Result & operator=(const Result &)=delete
Result(Result &&other)
Move a result and transfer its debug observation responsibility.
Definition Result.h:490
static Result failure(Status status)
Construct a failed void result from a structured status.
Definition Result.h:476
Result & operator=(Result &&other)
Move-assign after checking the destination's old result.
Definition Result.h:503
void expect(std::string_view message) const
Require success for a void operation.
Definition Result.h:582
static Result success(Status status)
Construct a successful void result with an explicit status.
Definition Result.h:468
static Result failure(Diagnostic diagnostic)
Construct a failed void result from one structured diagnostic.
Definition Result.h:484
const std::vector< Diagnostic > & diagnostics() const noexcept
Inspect all diagnostics; this counts as checking the Result.
Definition Result.h:535
void ignore(std::string_view reason={}) const noexcept
Explicitly discard this result after documenting the reason.
Definition Result.h:571
Result(const Result &)=delete
const Status & status() const noexcept
Inspect the structured operation status.
Definition Result.h:521
const Diagnostic * error() const noexcept
Inspect the first diagnostic, or null when none was supplied.
Definition Result.h:329
Result orElse(Function &&function) &&
Recover a failure with a function receiving its Status.
Definition Result.h:412
T valueOr(T fallback) &&
Return the value or an explicit alternate value, consuming this Result.
Definition Result.h:382
Result & operator=(Result< U > &&other)
Move-assign from a Result whose value converts to T by adding const.
Definition Result.h:274
const T & value() const &
Borrow the value from a const lvalue after checking success.
Definition Result.h:339
void ignore(std::string_view reason={}) const noexcept
Explicitly discard this result after documenting the reason.
Definition Result.h:424
Result & operator=(const Result &)=delete
Result(Result< U > &&other)
Convert a Result into a more const-qualified Result of the same outcome.
Definition Result.h:252
auto andThen(Function &&function) &&-> std::invoke_result_t< Function, T && >
Compose a successful value with a function returning another Result.
Definition Result.h:396
bool hasValue() const noexcept
Whether the result owns a value; observing this is a check.
Definition Result.h:293
const std::vector< Diagnostic > & diagnostics() const noexcept
Inspect all diagnostics; this counts as checking the Result.
Definition Result.h:314
Result(Result &&other)
Move a result and transfer its debug observation responsibility.
Definition Result.h:210
bool ok() const noexcept
Whether this result represents a non-failure outcome.
Definition Result.h:286
Result & operator=(Result &&other)
Move-assign a result after checking the destination's old result.
Definition Result.h:232
Result(const Result &)=delete
static Result success(T value, Status status)
Construct a successful result with an explicit non-error status.
Definition Result.h:188
const Status & status() const noexcept
Inspect the structured operation status.
Definition Result.h:300
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
static Result failure(Diagnostic diagnostic)
Construct a failed result from one structured diagnostic.
Definition Result.h:204
Debug-only observation token shared by Result<T> specializations.
Definition Result.h:65
void disarmObservation() noexcept
Drop observation duty; used when a moved-from result is empty.
Definition Result.h:109
~ResultObservation() noexcept(false)
Definition Result.h:78
ResultObservation() noexcept=default
Constructs a ResultObservation.
void assertCanBeOverwritten() const
Check the destination before a move under the caller's assertion policy.
Definition Result.h:93
void adoptObservationFrom(ResultObservation &other) noexcept
Adopt observation from.
Definition Result.h:102
ResultObservation(InactiveTag) noexcept
Definition Result.h:75
void requireObservation() noexcept
Require a fresh check after replacing the carried outcome.
Definition Result.h:112
True when From may convert into To only by adding const.
Definition Result.h:136
void moveAssignOptional(std::optional< T > &destination, std::optional< U > &&source)
Replace destination with source even when T is not assignable.
Definition Result.h:147
void failResultExpectation(const Status &status, std::string_view message, const char *file, unsigned line, bool assertionsEnabled)
Report a failed expect operation with its Status and caller context.
Definition Result.cpp:20
void checkResultInvariant(bool condition, const char *expression, const char *file, unsigned line, const char *message)
Check one Result invariant without instantiating the assertion backend in its caller.
Definition Result.cpp:6
bool everyResultValid(const Results &... results) noexcept
True only when every argument Result succeeded, observing all of them.
Definition Result.h:618
Definition Container.h:602
Start an inactive token used while a Result move is constructed.
Definition Result.h:74