expected: add trivial then
method.
This commit is contained in:
parent
4497c1ac97
commit
80e9542328
13
expected.hpp
13
expected.hpp
@ -9,7 +9,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <exception>
|
#include <exception>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
namespace cruft {
|
namespace cruft {
|
||||||
@ -83,7 +83,16 @@ namespace cruft {
|
|||||||
ValueT* operator-> (void)& { return &value (); }
|
ValueT* operator-> (void)& { return &value (); }
|
||||||
ValueT& operator* (void)& { return value (); }
|
ValueT& operator* (void)& { return value (); }
|
||||||
|
|
||||||
operator bool() const noexcept;
|
template <typename FunctionT, typename ...ArgsT>
|
||||||
|
expected then (FunctionT &&func, ArgsT &&...args)
|
||||||
|
{
|
||||||
|
if (!m_valid)
|
||||||
|
return *this;
|
||||||
|
else
|
||||||
|
return expected (std::invoke (func, args..., value ()));
|
||||||
|
}
|
||||||
|
|
||||||
|
explicit operator bool() const noexcept { return m_valid; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
union storage_t {
|
union storage_t {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user