C++ Logo

std-proposals

Advanced search

Re: Middle ground between "return" and exceptions?

From: Dmitry Dmitry <dimanne_at_[hidden]>
Date: Wed, 16 Sep 2020 08:24:54 +0100
>
> So it it's actually a nasty hack, which both looks like it was using
> coroutines, and simultaneously prevents you from actually using them as
> intended moving forward.
>
> > either false (in which case we effectively return from FindUsersCity and
> it corresponds to some error),
>
> And that's where you already fell for that misconception. It does not
> return from FindUsersCity, but it aborts execution of the whole coroutine
> context. Like an uncaught exception, unrolling the whole stack with it.
>

I might be wrong, but what do you think about this?
What if, instead of std::optional<> we have our own custom type (say,
Result<Ok, Err>) that will be aware of such a hackish usage of coroutines?
Resumable can be implicitly converted to Result<>. And when the return
value (Result<>) is initialised from Resumable it can destroy coroutine...
In this way we will not need a wrapper. Will it work? Am I right? :)

-- 
Dmitry
*Sent from gmail*

Received on 2020-09-16 02:25:25