tinypbrt 1.1.1
pbrt-v4 scene file parser for C11 with a header-only C++20 wrapper
Loading...
Searching...
No Matches
tpbrt::result< T > Struct Template Reference

Result of an operation: either a value or an error code (similar to C++23 std::expected). More...

#include <tinypbrt/detail/cpp/error.hpp>

Public Types

using value_type = T
 Value type.
 
using error_type = error
 Error type.
 
using variant_type = std::variant< value_type, error_type >
 Variant type of result.
 

Public Member Functions

constexpr result (const error_type err) noexcept
 Conversion constructor for error.
 
constexpr result (const value_type &val)
 Conversion constructor for value.
 
constexpr result (value_type &&val) noexcept(std::is_nothrow_move_constructible_v< value_type >)
 Conversion constructor for r-value value.
 
constexpr bool_t has_value () const noexcept
 Returns true if result has value.
 
constexpr operator bool () const noexcept
 Returns true if result has value.
 
constexpr error_type get_error () const noexcept
 Returns error code (error::NONE when result has value).
 
constexpr const value_type & get_value () const &
 Returns value (throws std::bad_variant_access when result holds an error).
 
constexpr value_type & get_value () &
 Returns value (throws std::bad_variant_access when result holds an error).
 
constexpr value_type && get_value () &&
 Returns value (throws std::bad_variant_access when result holds an error).
 
template<class U >
constexpr value_type value_or (U &&default_value) const &
 Returns value or given default value when result holds an error.
 
constexpr const variant_type & to_variant () const noexcept
 Conversion to variant.
 
template<class Visitor >
constexpr decltype(auto) visit (Visitor &&visitor) const
 Visits value or error.
 
constexpr const value_type & operator* () const &noexcept
 Returns value (unchecked, like std::optional).
 
constexpr value_type & operator* () &noexcept
 Returns value (unchecked, like std::optional).
 
constexpr value_type && operator* () &&noexcept
 Returns value (unchecked, like std::optional).
 
constexpr const value_type * operator-> () const noexcept
 Returns pointer to value (unchecked, like std::optional).
 
constexpr value_type * operator-> () noexcept
 Returns pointer to value (unchecked, like std::optional).
 
constexpr bool_t operator== (const result &rhs) const
 Equality operator.
 
constexpr bool_t operator== (const error_type err) const noexcept
 Equality operator (true when result holds given error).
 

Detailed Description

template<class T>
struct tpbrt::result< T >

Result of an operation: either a value or an error code (similar to C++23 std::expected).

A result never holds error::NONE: it is either a value or a real error.

Template Parameters
TType of value returned on success.

Member Typedef Documentation

◆ value_type

template<class T >
using tpbrt::result< T >::value_type = T

Value type.

◆ error_type

template<class T >
using tpbrt::result< T >::error_type = error

Error type.

◆ variant_type

template<class T >
using tpbrt::result< T >::variant_type = std::variant<value_type, error_type>

Variant type of result.

Constructor & Destructor Documentation

◆ result() [1/3]

template<class T >
constexpr tpbrt::result< T >::result ( const error_type  err)
inlineconstexprnoexcept

Conversion constructor for error.

◆ result() [2/3]

template<class T >
constexpr tpbrt::result< T >::result ( const value_type &  val)
inlineconstexpr

Conversion constructor for value.

◆ result() [3/3]

template<class T >
constexpr tpbrt::result< T >::result ( value_type &&  val)
inlineconstexprnoexcept

Conversion constructor for r-value value.

Member Function Documentation

◆ has_value()

template<class T >
constexpr bool_t tpbrt::result< T >::has_value ( ) const
inlineconstexprnoexcept

Returns true if result has value.

◆ operator bool()

template<class T >
constexpr tpbrt::result< T >::operator bool ( ) const
inlineexplicitconstexprnoexcept

Returns true if result has value.

◆ get_error()

template<class T >
constexpr error_type tpbrt::result< T >::get_error ( ) const
inlineconstexprnoexcept

Returns error code (error::NONE when result has value).

◆ get_value() [1/3]

template<class T >
constexpr const value_type & tpbrt::result< T >::get_value ( ) const &
inlineconstexpr

Returns value (throws std::bad_variant_access when result holds an error).

◆ get_value() [2/3]

template<class T >
constexpr value_type & tpbrt::result< T >::get_value ( ) &
inlineconstexpr

Returns value (throws std::bad_variant_access when result holds an error).

◆ get_value() [3/3]

template<class T >
constexpr value_type && tpbrt::result< T >::get_value ( ) &&
inlineconstexpr

Returns value (throws std::bad_variant_access when result holds an error).

◆ value_or()

template<class T >
template<class U >
constexpr value_type tpbrt::result< T >::value_or ( U &&  default_value) const &
inlineconstexpr

Returns value or given default value when result holds an error.

◆ to_variant()

template<class T >
constexpr const variant_type & tpbrt::result< T >::to_variant ( ) const
inlineconstexprnoexcept

Conversion to variant.

◆ visit()

template<class T >
template<class Visitor >
constexpr decltype(auto) tpbrt::result< T >::visit ( Visitor &&  visitor) const
inlineconstexpr

Visits value or error.

◆ operator*() [1/3]

template<class T >
constexpr const value_type & tpbrt::result< T >::operator* ( ) const &
inlineconstexprnoexcept

Returns value (unchecked, like std::optional).

◆ operator*() [2/3]

template<class T >
constexpr value_type & tpbrt::result< T >::operator* ( ) &
inlineconstexprnoexcept

Returns value (unchecked, like std::optional).

◆ operator*() [3/3]

template<class T >
constexpr value_type && tpbrt::result< T >::operator* ( ) &&
inlineconstexprnoexcept

Returns value (unchecked, like std::optional).

◆ operator->() [1/2]

template<class T >
constexpr const value_type * tpbrt::result< T >::operator-> ( ) const
inlineconstexprnoexcept

Returns pointer to value (unchecked, like std::optional).

◆ operator->() [2/2]

template<class T >
constexpr value_type * tpbrt::result< T >::operator-> ( )
inlineconstexprnoexcept

Returns pointer to value (unchecked, like std::optional).

◆ operator==() [1/2]

template<class T >
constexpr bool_t tpbrt::result< T >::operator== ( const result< T > &  rhs) const
inlineconstexpr

Equality operator.

◆ operator==() [2/2]

template<class T >
constexpr bool_t tpbrt::result< T >::operator== ( const error_type  err) const
inlineconstexprnoexcept

Equality operator (true when result holds given error).


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