Boost logo

Boost :

Subject: Re: [boost] [outcome] Change semantics on UB from peer review agreed semantics?
From: Andrzej Krzemienski (akrzemi1_at_[hidden])
Date: 2018-09-12 21:48:16


śr., 12 wrz 2018 o 23:19 Emil Dotchevski via Boost <boost_at_[hidden]>
napisał(a):

> On Wed, Sep 12, 2018 at 8:09 AM Steven Watanabe via Boost <
> boost_at_[hidden]> wrote:
>
> > What Niall's message fails to make clear is that
> > the actual choice is between UB and throwing an
> > exception. The compiler error is only to require
> > the user to make an explicit choice between the
> > two instead of letting the library choose.
> >
>
> It is still unclear to me how the user is making the choice. As far as I
> see it, except when exceptions are disabled (which is not standard C++),
> the point of using Outcome is to allow a function to return a "valueless"
> outcome instead of throwng an exception, which can now be postponed until
> the value is requested; so, if I want the exception, I can just say
> foo().value(). This simplifies APIs which would otherwise have to provide
> two variants for a function, one that throws and one that does not.
>
> Can someone clarify?
>

You have just described something that one could call "value or throw"
idiom: `foo().value()`. It will only work under certain policies:

template <typename T>
using resultA = result<T, std::error_code,
error_code_throw_as_system_error<T, EC, void>>;
// the above will throw on value from valueless

template <typename T>
using resultB = result<T, std::error_code, all_narrow>;
// the above will be UB on value from valueless

template <typename T>
using resultC = result<T, std::error_code>;
// the above will throw on value from valueless
// (third argument defaults to default_policy<T, std::error_code, void>
which throws for std::error_code)

template <typename T>
using resultC = result<T, MyErrorCode>;
// the above will be *UB* on value from valueless, because default_policy
is UB for unknown (to the framework) types.

The fourth case is described as it works today. The proposal in this thread
is to change the fourth case so that default_policy fails to compile when
used for unknown types.

Does the above answer your question?

Regards,
&rzej;


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk