LiveKit C++ Client SDK v1.1.0
Real-time audio/video/data SDK for C++
Loading...
Searching...
No Matches
livekit::Result< T, E > Class Template Reference

Lightweight success-or-error return type for non-exceptional API failures. More...

#include <result.h>

Public Member Functions

bool ok () const noexcept
 True when the result contains a success value.
 
bool hasError () const noexcept
 True when the result contains an error.
 
 operator bool () const noexcept
 Allows if (result) style success checks.
 
T & value () &
 Access the success value.
 
const T & value () const &
 Access the success value.
 
T && value () &&
 Move the success value out.
 
const T && value () const &&
 Move the success value out.
 
E & error () &
 Access the error value.
 
const E & error () const &
 Access the error value.
 
E && error () &&
 Move the error value out.
 
const E && error () const &&
 Move the error value out.
 

Static Public Member Functions

template<typename U = T, typename = std::enable_if_t<std::is_constructible<T, U&&>::value>>
static Result success (U &&value)
 Construct a successful result containing a value.
 
template<typename F = E, typename = std::enable_if_t<std::is_constructible<E, F&&>::value>>
static Result failure (F &&error)
 Construct a failed result containing an error.
 

Detailed Description

template<typename T, typename E>
class livekit::Result< T, E >

Lightweight success-or-error return type for non-exceptional API failures.

This is intended for SDK operations where callers are expected to branch on success vs. failure, such as back-pressure or an unpublished track.

Result<T, E> stores either:

  • a success value of type T, or
  • an error value of type E

Accessors validate their preconditions before returning. Calling value() on an error result, or error() on a success result, throws std::logic_error. Avoid this by checking ok() / hasError() / if (result) before calling value() or error().

Member Function Documentation

◆ error() [1/4]

template<typename T , typename E >
E & livekit::Result< T, E >::error ( ) &
inline

Access the error value.

Exceptions
std::logic_errorif hasError() == false.

◆ error() [2/4]

template<typename T , typename E >
E && livekit::Result< T, E >::error ( ) &&
inline

Move the error value out.

Exceptions
std::logic_errorif hasError() == false.

◆ error() [3/4]

template<typename T , typename E >
const E & livekit::Result< T, E >::error ( ) const &
inline

Access the error value.

Exceptions
std::logic_errorif hasError() == false.

◆ error() [4/4]

template<typename T , typename E >
const E && livekit::Result< T, E >::error ( ) const &&
inline

Move the error value out.

Exceptions
std::logic_errorif hasError() == false.

◆ value() [1/4]

template<typename T , typename E >
T & livekit::Result< T, E >::value ( ) &
inline

Access the success value.

Exceptions
std::logic_errorif ok() == false.

◆ value() [2/4]

template<typename T , typename E >
T && livekit::Result< T, E >::value ( ) &&
inline

Move the success value out.

Exceptions
std::logic_errorif ok() == false.

◆ value() [3/4]

template<typename T , typename E >
const T & livekit::Result< T, E >::value ( ) const &
inline

Access the success value.

Exceptions
std::logic_errorif ok() == false.

◆ value() [4/4]

template<typename T , typename E >
const T && livekit::Result< T, E >::value ( ) const &&
inline

Move the success value out.

Exceptions
std::logic_errorif ok() == false.

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