expected: add trivial then method.

This commit is contained in:
Danny Robson 2019-02-07 17:33:47 +11:00
parent 4497c1ac97
commit 80e9542328

View File

@ -9,7 +9,7 @@
#pragma once
#include <exception>
#include <functional>
///////////////////////////////////////////////////////////////////////////////
namespace cruft {
@ -83,7 +83,16 @@ namespace cruft {
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:
union storage_t {