litert::
Expected
#include <litert_expected.h>
A utility for generic return values that may represent a failure.
Summary
Expected
stores and owns the lifetime of either an Unexpected
object or a value of type T
. T
can be any primitive or non-primitive type.
No dynamic allocations occur during initialization, so the underlying T
is only movable (as opposed to being releasable). Arguments should be constructed in-place when initializing the Expected
object if possible.
Unexpected
&&
and T&&
can be implicitly cast to an Expected
. For example:
ExpectedBar () { bool success = ... if (!success) { return Unexpected( Status : : kErrorUnknown , "Bad Baz" ); } return Foo (); }
Public types
std::conditional_t< std::is_reference_v< T >, std::reference_wrapper< std::remove_reference_t< T >>, T >
const value_type
*
const value_type
&
std::remove_reference_t< T > *
std::remove_reference_t< T > &
std::decay_t< T >
Public functions
Error
() const &&=delete
Error
()&&=delete
Value
() const &
const_reference
T
value. Value
()&
reference
Value
() const &&=delete
reference &
Value
()&&=delete
reference &
operator bool
() const
bool
for HasValue
. operator*
() const &
const_reference
operator*
()&
reference
operator*
() const &&=delete
reference &
operator*
()&&=delete
reference &
operator->
() const &
const_pointer
operator->
()&
pointer
operator->
() const &&=delete
const_pointer
operator->
()&&=delete
pointer
Public types
StorageType
std::conditional_t< std::is_reference_v< T >, std::reference_wrapper< std::remove_reference_t< T >>, T > StorageType
const_pointer
const value_type * const_pointer
const_reference
const value_type & const_reference
pointer
std::remove_reference_t< T > * pointer
reference
std::remove_reference_t< T > & reference
value_type
std :: decay_t < T > value_type
The following type definitions are in snake_case to match standard member types.
Public attributes
unexpected_
Unexpected unexpected_
value_
StorageType value_
Public functions
Error
const class Error & Error () const &
Observer for Unexpected
.
The program exits if it doesn't have one.
Error
class Error & Error ()&
Error
const class Error && Error () const && = delete
Deleted: an Expected
should always be checked before accessing its error.
Error
class Error && Error ()&&= delete
Deleted: an Expected
should always be checked before accessing its error.
Expected
Expected( std::initializer_list< U > il )
Constructs T
from an initializer list in-place.
Expected
Expected( Args &&... args )
Constructs T
from forwarded arguments in-place.
Expected
Expected( reference t )
Allows for implicit conversion from a convertible T
value in-place.
Expected
Expected ( const U & t )
Copy-constructs from a constant reference.
This is disabled if T
is a constant reference.
Expected
Expected ( value_type && t )
Expected
Expected ( const Unexpected & err )
Constructs from an Unexpected
object in-place.
Allows for implicit conversion from Error
.
Expected
Expected( Unexpected && err )
Expected
Expected ( const class Error & e )
Expected
Expected( Expected && other )
Expected
Expected ( const Expected & other )
HasValue
bool HasValue () const
Checks if this Expected
contains a T
value.
If not, it contains an Unexpected
.
Value
const_reference Value () const &
Observers for the T
value.
The program exits if it doesn't have one.
Value
reference Value()&
Value
reference & Value () const && = delete
Deleted: an Expected
should always be checked before accessing its value.
Value
reference & Value()&&=delete
Deleted: an Expected
should always be checked before accessing its value.
operator bool
operator bool () const
Converts to bool
for HasValue
.
operator*
const_reference operator * () const &
operator*
reference operator*()&
operator*
reference & operator * () const && = delete
Deleted: an Expected
should always be checked before accessing its value.
operator*
reference & operator*()&&=delete
Deleted: an Expected
should always be checked before accessing its value.
operator->
const_pointer operator - > () const &
operator->
pointer operator->()&
operator->
const_pointer operator - > () const && = delete
Deleted: an Expected
should always be checked before accessing its value.
operator->
pointer operator->()&&=delete
Deleted: an Expected
should always be checked before accessing its value.
~Expected
~Expected()

