Код: Выделить всё
expected getA(const X& x);
expected getB(const Y& y);
C compute_all(const A& a, const B& b);
Код: Выделить всё
auto a_ret = getA(x);
if (!a_ret)
return a_ret.error();
auto b_ret = getB(y);
if (!b_ret)
return b_ret.error();
C final_ret = compute_all(*a_ret, *b_ret);
Код: Выделить всё
expected final_ret = magic_apply(compute_all, getA(x), getB(y))
Код: Выделить всё
template
auto magic_apply(Func func, const std::expected& a, const std::expected& b)
->
std::expected
{
if(!a) {
return std::unexpected{ a.error() };
}
if(!b) {
return std::unexpected{ b.error() };
}
return func(a.value(), b.value());
}
Подробнее здесь: https://stackoverflow.com/questions/787 ... tdexpected