Boost logo

Boost :

From: Bjorn Reese (breese_at_[hidden])
Date: 2020-05-31 13:50:43

On 2020-05-31 01:18, Emil Dotchevski via Boost wrote:

>> The LEAF handling is reminiscient of a variant visitor, but with the
>> variants we can use index() and std::get<T> in a switch statement
>> instead of visitation. I would like to see something similar for LEAF
>> error contexts.
> The difficulty with that is, context<E...> requires a list of types so it
> knows what to put in the tuple. In other words, before you are able to say
> ctx.get<T>(), you must have included that T in the types used to
> instantiate context<E...>, and if you didn't, you'd always get a null.
> Worse, if you missed to include a T in the list of types, and an
> error-reporting function attempts to communicate a T, it'll get discarded
> (no storage for it). That's why LEAF deduces the E... type list from the
> types that error handlers take as arguments. This way, if a T is discarded,
> it means no error handlers needed it, and so it'd be wasteful to spend
> cycles transporting it.

I made a typo above. I meant to say std::get<I>.

I am asking for a low-level API, not a bullet-proof API. If the latter
is needed, then your existing pattern matching solution works just fine.

The use of such a low-level API would look something like this:

   leaf::context<E0, E1> ctx;
   ctx.activate(); // I would like to avoid this though

   auto ret = foo();
   if (!ret)
     switch (ctx.index(ret.error()))
     case 0: // E0
       handle_E0(ctx.get<0>(ret.error()); break;

     case 1: // E1
       handle_E1(ctx.get<1>(ret.error()); break;

     default: // Unknown error type
       panic(); break;

Boost list run by bdawes at, gregod at, cpdaniel at, john at