cppfig 0.1.0
Modern C++20 compile-time type-safe configuration library
Loading...
Searching...
No Matches
cppfig::StatusOr< T > Class Template Reference

A value-or-error type, similar to std::expected (C++23). More...

#include <status.h>

Public Member Functions

 StatusOr (T value)
 Constructs a StatusOr holding a value (implicit conversion).
 
 StatusOr (Status status)
 Constructs a StatusOr holding an error status.
 
auto ok () const noexcept -> bool
 Returns true if a value is present (no error).
 
auto status () const &-> Status
 Returns the error status.
 
auto status () &&-> Status
 Returns the error status (move).
 
auto value () const &-> const T &
 Returns a const reference to the value.
 
auto value () &&-> T &&
 Returns an rvalue reference to the value.
 
auto operator* () const &-> const T &
 Dereferences to the stored value (const).
 
auto operator* () &&-> T &&
 Dereferences to the stored value (move).
 
auto operator-> () const -> const T *
 Arrow operator for member access on the stored value.
 

Detailed Description

template<typename T>
class cppfig::StatusOr< T >

A value-or-error type, similar to std::expected (C++23).

Holds either a successfully computed value of type T, or a Status describing why the computation failed. Provides an interface compatible with the subset of absl::StatusOr used by cppfig.

Template Parameters
TThe value type. Must not be Status.

Constructor & Destructor Documentation

◆ StatusOr() [1/2]

template<typename T >
cppfig::StatusOr< T >::StatusOr ( value)
inline

Constructs a StatusOr holding a value (implicit conversion).

◆ StatusOr() [2/2]

template<typename T >
cppfig::StatusOr< T >::StatusOr ( Status  status)
inline

Constructs a StatusOr holding an error status.

Precondition
status must not be OK.

Member Function Documentation

◆ ok()

template<typename T >
auto cppfig::StatusOr< T >::ok ( ) const -> bool
inlinenoexcept

Returns true if a value is present (no error).

◆ operator*() [1/2]

template<typename T >
auto cppfig::StatusOr< T >::operator* ( ) && -> T&&
inline

Dereferences to the stored value (move).

◆ operator*() [2/2]

template<typename T >
auto cppfig::StatusOr< T >::operator* ( ) const & -> const T&
inline

Dereferences to the stored value (const).

◆ operator->()

template<typename T >
auto cppfig::StatusOr< T >::operator-> ( ) const -> const T*
inline

Arrow operator for member access on the stored value.

◆ status() [1/2]

template<typename T >
auto cppfig::StatusOr< T >::status ( ) && -> Status
inline

Returns the error status (move).

◆ status() [2/2]

template<typename T >
auto cppfig::StatusOr< T >::status ( ) const & -> Status
inline

Returns the error status.

Returns an OK status if a value is present.

◆ value() [1/2]

template<typename T >
auto cppfig::StatusOr< T >::value ( ) && -> T&&
inline

Returns an rvalue reference to the value.

Precondition
ok() must be true.

◆ value() [2/2]

template<typename T >
auto cppfig::StatusOr< T >::value ( ) const & -> const T&
inline

Returns a const reference to the value.

Precondition
ok() must be true.

The documentation for this class was generated from the following file: