ClikaRT::Result
class
Header: ClikaRT/common/result.h
Template: template <``typename T``>
Holds either a success value of type T or a (Status, message) failure. Move-only. Check ok() before reading value(), or use value_or_throw(). [[nodiscard]]: a call that returns a Result and discards it swallows the failure it may carry; the compiler warns at such a site; consume it (unwrap, CLIKART_CHECK, a named read) or discard deliberately with a (void) cast.
Member functions
Result(T)
Result(T value)
Success.
Declared in ClikaRT/common/result.h, line 184
Result(Status, string)
Result(Status status, std::string message = std::string())
Failure (a Status other than Ok, with an optional message).
Declared in ClikaRT/common/result.h, line 189
Result(Status, string, string)
Result(
Status status,
std::string message,
std::string code_name
)
Failure carrying the fine-grained status NAME the failure originated with (see code_name()).
Declared in ClikaRT/common/result.h, line 195
Result(Result)
Result(Result&& other)
Move: transfers the payload or the failure state.
Declared in ClikaRT/common/result.h, line 202
operator=(Result)
Move-assign: transfers the payload or the failure state.
Declared in ClikaRT/common/result.h, line 208
Result(Result)
Result(const Result&) =delete
Declared in ClikaRT/common/result.h, line 219
operator=(Result)
Declared in ClikaRT/common/result.h, line 220
~Result()
~Result()
Destroys the held value, when one is present.
Declared in ClikaRT/common/result.h, line 222
ok()
bool ok() const noexcept
True on success.
Declared in ClikaRT/common/result.h, line 225
operator bool()
explicit operator bool() const noexcept
Tests OKNESS: if (auto r = ...). NOTE: on a Result<bool> this is NOT the payload; read value() for the answer (bool payloads are excluded from implicit extraction so this stays the ONLY bool conversion).
Declared in ClikaRT/common/result.h, line 230
status()
Status status() const noexcept
the coarse status; Ok on success
Declared in ClikaRT/common/result.h, line 231
message()
const std::string& message() const noexcept
Diagnostic message; empty on success. A failure you can act on reads as plain text in every build and names the value it refuses; a message of the form E<digits> is an internal fault code, build-specific and never an identifier to record or compare (report it verbatim with the runtime version, and branch on code_name()).
Declared in ClikaRT/common/result.h, line 237
code_name()
const std::string& code_name() const noexcept
The stable NAME of the fine-grained status the failure originated with (e.g. "TIMED_OUT"); empty on success and for a failure that did not originate inside the runtime. Machine-readable in EVERY build; it survives release obfuscation even when message() is an opaque code; status() remains the coarse switch.
Declared in ClikaRT/common/result.h, line 243
value()
T& value() noexcept
The value. Precondition: ok().
Declared in ClikaRT/common/result.h, line 246
value()
const T& value() const noexcept
const access; same precondition
Declared in ClikaRT/common/result.h, line 247
value_or_throw()
T value_or_throw()
Move the value out, or raise on failure (throws ClikaRT::Error, or aborts with a diagnostic when exceptions are disabled).
Declared in ClikaRT/common/result.h, line 251
operator typename std::conditional< std::is_same< typename std::remove_cv< T >::type, bool >::value, detail::NoImplicitBoolExtraction, T >::type()
operator typename std::conditional< std::is_same< typename std::remove_cv< T >::type, bool >::value, detail::NoImplicitBoolExtraction, T >::type(
) &&
Implicit extraction from a TEMPORARY result (T x = fn(...);, g(fn(...))), moving the value out or raising exactly as value_or_throw(), so value-shaped call sites keep compiling under the Result-returning surface and adopt explicit handling at their own pace. A plain (non-template) conversion so overload resolution and standard-conversion tails match the value-returning surface exactly (long n = size_fn();, g(int) vs g(long) picks as it would on a bare int). Deliberately rvalue-only (a named Result is read through ok()/value()/unwrap), and bool payloads are excluded (the conversion target degrades to an unusable detail tag): operator bool means OKNESS everywhere, never the payload. Note a bool DESTINATION fed by a non-bool payload still follows the payload's own conversion (bool any = count_fn(); and if (count_fn()) test != 0, raising on failure, as the value surface would); the okness test is the named form, if (auto r = fn()), where this rvalue-qualified conversion is not viable.
Declared in ClikaRT/common/result.h, line 273