载入中...
搜索中...
未找到
Result.h
浏览该文件的文档.
49 EV_ASSERT(observationSatisfied, "Result destroyed without checking; inspect it or call ignore() explicitly");
155class [[nodiscard("Result must be checked or explicitly ignored")]] Result : private detail::ResultObservation {
156 static_assert(!std::is_reference_v<T>, "Result<T> cannot hold a reference; use a handle or value");
164 static Result success(T value) { return Result(Status::success(), std::optional<T>(std::move(value))); }
183 static Result failure(Diagnostic diagnostic) { return failure(Status::failure(std::move(diagnostic))); }
433class [[nodiscard("Result must be checked or explicitly ignored")]] Result<void> : private detail::ResultObservation {
455 static Result failure(Diagnostic diagnostic) { return failure(Status::failure(std::move(diagnostic))); }
463 : detail::ResultObservation(detail::ResultObservation::InactiveTag{}), status_(std::move(other.status_)) {
EVEngine assertion entry point, backed by zeroerr.
#define EV_ASSERT(cond,...)
Assert an internal engine invariant (state that must always hold).
Definition Assert.h:37
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:516
bool ok() const noexcept
Whether this result represents a non-failure outcome.
Definition Result.h:480
Result & operator=(const Result &)=delete
Result(Result &&other)
Move a result and transfer its debug observation responsibility.
Definition Result.h:461
static Result failure(Status status)
Construct a failed void result from a structured status.
Definition Result.h:447
void expect(std::string_view message) const
Require success for a void operation.
Definition Result.h:548
static Result success(Status status)
Construct a successful void result with an explicit status.
Definition Result.h:439
static Result failure(Diagnostic diagnostic)
Construct a failed void result from one structured diagnostic.
Definition Result.h:455
const std::vector< Diagnostic > & diagnostics() const noexcept
Inspect all diagnostics; this counts as checking the Result.
Definition Result.h:501
Result & operator=(Result &&other)
Move-assign after checking the destination's old result.
Definition Result.h:469
void ignore(std::string_view reason={}) const noexcept
Explicitly discard this result after documenting the reason.
Definition Result.h:537
Result(const Result &)=delete
const Status & status() const noexcept
Inspect the structured operation status.
Definition Result.h:487
const Diagnostic * error() const noexcept
Inspect the first diagnostic, or null when none was supplied.
Definition Result.h:298
Result orElse(Function &&function) &&
Recover a failure with a function receiving its Status.
Definition Result.h:381
T valueOr(T fallback) &&
Return the value or an explicit alternate value, consuming this Result.
Definition Result.h:351
const T & value() const &
Borrow the value from a const lvalue after checking success.
Definition Result.h:308
void ignore(std::string_view reason={}) const noexcept
Explicitly discard this result after documenting the reason.
Definition Result.h:393
Result & operator=(const Result &)=delete
Result & operator=(Result< U > &&other)
Move-assign from a Result whose value converts to T by adding const.
Definition Result.h:243
Result(Result< U > &&other)
Convert a Result into a more const-qualified Result of the same outcome.
Definition Result.h:225
auto andThen(Function &&function) &&-> std::invoke_result_t< Function, T && >
Compose a successful value with a function returning another Result.
Definition Result.h:365
bool hasValue() const noexcept
Whether the result owns a value; observing this is a check.
Definition Result.h:262
Result & operator=(Result &&other)
Move-assign a result after checking the destination's old result.
Definition Result.h:205
const std::vector< Diagnostic > & diagnostics() const noexcept
Inspect all diagnostics; this counts as checking the Result.
Definition Result.h:283
Result(Result &&other)
Move a result and transfer its debug observation responsibility.
Definition Result.h:189
bool ok() const noexcept
Whether this result represents a non-failure outcome.
Definition Result.h:255
Result(const Result &)=delete
static Result success(T value, Status status)
Construct a successful result with an explicit non-error status.
Definition Result.h:167
const Status & status() const noexcept
Inspect the structured operation status.
Definition Result.h:269
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:175
static Result failure(Diagnostic diagnostic)
Construct a failed result from one structured diagnostic.
Definition Result.h:183
Debug-only observation token shared by Result<T> specializations.
Definition Result.h:32
void disarmObservation() noexcept
Drop observation duty; used when a moved-from result is empty.
Definition Result.h:84
~ResultObservation() noexcept(false)
Definition Result.h:47
ResultObservation() noexcept=default
Constructs a ResultObservation.
void adoptObservationFrom(ResultObservation &other) noexcept
Adopt observation from.
Definition Result.h:73
ResultObservation(InactiveTag) noexcept
Definition Result.h:42
void requireObservation() noexcept
Require a fresh check after replacing the carried outcome.
Definition Result.h:91
True when From may convert into To only by adding const.
Definition Result.h:117
void moveAssignOptional(std::optional< T > &destination, std::optional< U > &&source)
Replace destination with source even when T is not assignable.
Definition Result.h:129
bool everyResultValid(const Results &... results) noexcept
True only when every argument Result succeeded, observing all of them.
Definition Result.h:586
Definition Container.h:602
Start an inactive token used while a Result move is constructed.
Definition Result.h:41