66 template<
typename RES>
83 : failure_{success? nullptr:
std::make_exception_ptr (
error::State{
"operation failed"})}
88 : failure_{
std::make_exception_ptr (reason)}
92 template<
class FUN,
typename...ARGS,
typename=
lib::meta::enable_if<std::is_invocable<FUN,ARGS...>>>
93 Result (FUN&& callable, ARGS&& ...args) noexcept
97 static_assert (std::is_invocable_v<FUN,ARGS...>);
98 std::invoke (std::forward<FUN>(callable)
99 ,std::forward<ARGS>(args)...
104 failure_ = std::current_exception();
109 operator bool()
const {
return isValid(); }
116 std::rethrow_exception(failure_);
130 template<
typename RES>
143 template<
typename=lib::meta::disable_if<std::is_invocable<RES>>>
146 , value_{std::forward<RES> (value)}
150 template<
class FUN,
typename...ARGS,
typename=
lib::meta::enable_if<std::is_invocable<FUN,ARGS...>>>
151 Result (FUN&& callable, ARGS&& ...args) noexcept
156 static_assert (std::is_invocable_r_v<RES,FUN,ARGS...>);
157 value_ = std::invoke_r<RES> (std::forward<FUN>(callable)
158 ,std::forward<ARGS>(args)...
163 failure_ = std::current_exception();
176 template<
typename TY =RES>
181 return static_cast<TY
> (*value_);
188 return isValid()? *value_ : std::forward<O> (defaultVal);
191 template<
typename MAKE,
typename...ARGS>
198 return std::invoke(std::forward<MAKE> (producer), std::forward<ARGS> (args)...);
203 template<
typename VAL,
typename=lib::meta::disable_if<std::is_invocable<VAL>>>
207 template<
typename FUN,
typename...ARGS>
208 Result (FUN&&, ARGS&&...) ->
Result<std::invoke_result_t<FUN,ARGS...>>;
Result(lumiera::Error const &reason)
failed result, with reason given.
std::exception_ptr failure_
Result(bool success=false)
mark either failure (default) or success
Result(FUN &&callable, ARGS &&...args) noexcept
invoke a callable and mark success or failure
Representation of the result of some operation, EITHER a value or a failure.
Result(lumiera::Error const &reason)
mark failed result, with reason given.
RES value_or(O &&defaultVal)
Result(RES &&value)
standard case: valid result
RES or_else(MAKE &&producer, ARGS ...args)
wrapper::ItemWrapper< RES > value_
Result(FUN &&callable, ARGS &&...args) noexcept
invoke a callable and capture result in one shot
Universal value/ref wrapper accessible similar to a pointer.
Interface and Base definition for all Lumiera Exceptions.
Lumiera error handling (C++ interface).
Adapter to store and hold an element of arbitrary type in local storage.
Implementation namespace for support and library code.
Result(VAL &&) -> Result< VAL >
deduction guide: allow perfect forwarding of a any result into the ctor call.