Skip to main content

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 186

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 191

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 197

Result(Result)​

Result(Result&& other)

Move: transfers the payload or the failure state.

Declared in ClikaRT/common/result.h, line 204

operator=(Result)​

Result& operator=(Result&& other)

Move-assign: transfers the payload or the failure state.

Declared in ClikaRT/common/result.h, line 210

Result(Result)​

Result(const Result&) =delete

Declared in ClikaRT/common/result.h, line 221

operator=(Result)​

Result& operator=(const Result&) =delete

Declared in ClikaRT/common/result.h, line 222

~Result()​

~Result()

Destroys the held value, when one is present.

Declared in ClikaRT/common/result.h, line 224

ok()​

bool ok() const noexcept

True on success.

Declared in ClikaRT/common/result.h, line 227

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 232

status()​

Status status() const noexcept

the coarse status; Ok on success

Declared in ClikaRT/common/result.h, line 233

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 239

code_name()​

const std::string& code_name() const noexcept

The stable NAME the failure originated with: a runtime status name (e.g. "TIMED_OUT") or the name a consumer's model minted (an Error raised inside a phase body crosses the engine and comes back with its own code_name unchanged); empty on success and for a failure that carries no name. 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 247

value()​

T& value() noexcept

The value. Precondition: ok().

Declared in ClikaRT/common/result.h, line 250

value()​

const T& value() const noexcept

const access; same precondition

Declared in ClikaRT/common/result.h, line 251

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 255

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 277