Boost logo

Boost :

Subject: Re: [boost] Noexcept
From: Andrzej Krzemienski (akrzemi1_at_[hidden])
Date: 2017-06-20 06:34:14

2017-06-20 0:42 GMT+02:00 Richard Hodges via Boost <boost_at_[hidden]>:

> > To somewhat challenge this statement, The following is an example of how
> I
> > would use Boost.Outcome if I had it available at the time when I was
> > solving this parsing problem:
> >
> In the above code, the return type of expected<std::vector<Distrib>,
> BadInput> is equivalent in all respects to 2-state variant.

Conceptually, yes.

> If it were implemented as a boost/std::variant, then the two states could
> be handled with a static visitor - which would provide a compile-time
> guarantee that any future third state was not missed.

When I use `expected` I also get a guarantee that there will always be two
types to handle - no more.

What I also gain is the ability to use the TRY operation, which makes the
program twice shorter, while not compromising clarity or type safety.

> I don't think we're gaining anything with outcome, other than perhaps a
> label which serves to express intent?

Yes, it is mostly for: clarity of intent, terseness, static safety (invalid
usages detected at compile-time).


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