Boost logo

Boost :

Subject: Re: [boost] [outcome] expected, etc. why are these assignable
From: Robert Ramey (ramey_at_[hidden])
Date: 2017-06-02 16:55:25


On 6/2/17 9:22 AM, Richard Hodges via Boost wrote:
> Forgive me chiming in late, but what is the semantic difference between:
>
> enum class no_difference
> {
> _
> }
>
> expected<std::path, no_difference, std::error_code, std::exception_ptr>
>
> and this:
>
> using path_difference = std::variant<std::path, no_difference>;
> using error = std::variant<std::error_code, std::exception_ptr>;
>
> expected<path_difference, error> return_first_diff(...);
>
> Doesn't the latter form satisfy all concerns in that:
> 1. It conforms to a desirable 2-state 'value or error' KISS paradigm.
> 2. it contains all the information we'll ever need.
> 3. success code paths are now co-located, as are failure code paths. There
> is no need for N code-paths to cater for N states. Isn't this more
> maintainable?

Right. By leaving the second parameter E as a template parameter, it
can contain as much state or as little state as one wants. Your
formulation might be considered more heavy weight - but hey, that's up
to the user - not us.

Robert Ramey


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