template class EE::Result¶
Overview¶
A synchronous success-or-error value. More…
#include <result.hpp> template <typename T, typename E> class Result { public: // typedefs typedef T ValueType; typedef E ErrorType; // fields T mValue; E mError; // construction template <typename U, std::enable_if_t<std::is_constructible_v<T, U&&>, int> = 0> Result(OkValue<U>&& ok); template <typename U, std::enable_if_t<std::is_constructible_v<T, const U&>, int> = 0> Result(const OkValue<U>& ok); template <typename G, std::enable_if_t<std::is_constructible_v<E, G&&>, int> = 0> Result(ErrValue<G>&& err); template <typename G, std::enable_if_t<std::is_constructible_v<E, const G&>, int> = 0> Result(const ErrValue<G>& err); Result(const Result& other); Result(Result&& other); ~Result(); // methods Result& operator=(const Result& other); Result& operator=(Result&& other); bool hasValue() const; bool hasError() const; operator bool() const; T& value(); const T& value() const; T&& value(); E& error(); const E& error() const; E&& error(); T* operator->(); const T* operator->() const; T& operator*(); const T& operator*() const; T&& operator*(); };
Detailed Documentation¶
A synchronous success-or-error value.
Result<T, E> holds either a T or an E, stored inline in a union. It has no threading or async semantics. Payload construction and assignment can propagate exceptions; accessing the inactive member is a contract violation reported by a debug assertion. Move-only types are supported. Assignment requires at least one alternative to be nothrow move-constructible, so a failed cross-alternative construction preserves the destination’s previous alternative and value. Assignment within one alternative follows that payload’s exception guarantee.
Result<VFSFileInfo, VFSError> statResult = Ok( std::move( info ) ); if ( statResult ) consume( statResult.value() ); else report( statResult.error() );