OptrisOptrisDocumentation

Documentation/OTC SDK/OTC SDK — C++ API referencev12.0

optris::sdk::Expected

A value or the error explaining its absence.

Warning: Internal. See the note at the top of this header: this type does not cross into the C ABI or the .NET package, and must not appear on a new external API surface.

Template parameters

Name Description
T Value type; use void for operations that only succeed or fail.
E Error type, normally Error<SomeEnum>`.

Public types

value_type

T value_type

The value type, or void.

error_type

E error_type

The error type, normally Error<SomeEnum>`.

Public functions

Expected

constexpr Expected()

A default-constructed value, for the return {}; form. Present only when T allows it, exactly as std::expected's is.

Expected

constexpr Expected(U &&value)

A value, implicitly, so return frame; works.

Constrained away from both unexpected-wrappers and from Expected itself, so return std::unexpected(MakeError(...)) takes the constructor below rather than trying to build a T out of it.

Expected

constexpr Expected(U &&unex)

The error arm. Takes optris::sdk::Unexpected<E>, and anything else shaped like it -- which is how the internal std::unexpected(...)` sites bind. See detail::IsUnexpectedLike.

has_value

constexpr bool has_value() const noexcept

Returns: True when this holds a value rather than an error.

operator bool

constexpr operator bool() const noexcept

Returns: has_value(), so a call site reads if (!result).

operator*

constexpr const T & operator*() const &

Returns: The value, unchecked. Undefined if there is none -- check first, or call value().

operator*

constexpr T & operator*() &

Returns: The value, unchecked.

operator*

constexpr T && operator*() &&

Returns: The value, unchecked, moved out.

operator->

constexpr const T * operator->() const

Returns: A pointer to the value, unchecked.

operator->

constexpr T * operator->()

Returns: A pointer to the value, unchecked.

value

const T & value() const &

Returns: The value.

Exceptions

Name Description
BadResultAccess if there is none.

value

T & value() &

Returns: The value.

Exceptions

Name Description
BadResultAccess if there is none.

value

T && value() &&

Returns: The value, moved out.

Exceptions

Name Description
BadResultAccess if there is none.

error

constexpr const E & error() const &

Returns: The error. Undefined when has_value() is true.

error

constexpr E & error() &

Returns: The error. Undefined when has_value() is true.

error

constexpr E && error() &&

Returns: The error, moved out.

value_or

constexpr T value_or(U &&fallback) const &

Parameters

Name Description
fallback Returned when there is no value.

Returns: The value, or fallback.