Lumiera  0.pre.03
»edit your freedom«
result.hpp File Reference

Go to the source code of this file.

Description

Intermediary value object to represent »either« an operation result or a failure.

Some operation might have produced a value result or failed with an exception. Typically, the Result token is used inline — immediately either invoking one of the member function or employing the built-in result type conversion. It will be copyable iff the result value is copyable. There is an implicit valid or failure state, which can be tested. Any attempt to get the value of an invalid result token will cause an exception to be thrown.

  • Result<void>(bool) can be used as a success marker
  • a Result instance can be created by perfect forwarding from any type
  • any exception is supported for failure, wile direct construction is limited to lumiera::Error (to avoid ambiguities in ctor overload resolution)
  • an arbitrary functor or callable can be invoked, capturing the result.
    Todo:
    an option-style interface could be provided for the »right value« (i.e. the exception caught), in case this turns out to be of any use; this kind of API design however is anything than trivial, given that any value can be thrown as exception in C++
    See also
    vault::ThreadJoinable usage example

Definition in file result.hpp.

#include "lib/error.hpp"
#include "lib/wrapper.hpp"
#include "lib/meta/util.hpp"
#include "lib/null-value.hpp"
#include <type_traits>
#include <exception>
#include <utility>

Classes

class  Result< RES >
 Representation of the result of some operation, EITHER a value or a failure. More...
 
class  Result< RES >
 Representation of the result of some operation, EITHER a value or a failure. More...
 
class  Result< void >
 The base case is just to capture success or failure, without returning any value result. More...
 

Functions

template<class FUN , typename... ARGS>
auto failsafeInvoke (std::exception_ptr &capturedFailure, FUN &&callable, ARGS &&...args) noexcept
 Helper to invoke an arbitrary callable in a failsafe way. More...
 
template<typename VAL , typename = lib::meta::disable_if<std::is_invocable<VAL>>>
 Result (VAL &&) -> Result< VAL >
 deduction guide: allow perfect forwarding of a any result into the ctor call. More...
 
template<typename FUN , typename... ARGS>
 Result (FUN &&, ARGS &&...) -> Result< std::invoke_result_t< FUN, ARGS... >>
 deduction guide: find out about result value to capture from a generic callable. More...
 

Namespaces

 lib
 Implementation namespace for support and library code.