Boost logo

Boost :

Subject: Re: [boost] Interest in an 'either' library?
From: Pierre T. (ptalbot_at_[hidden])
Date: 2013-06-24 07:20:56


Hello

> For example, compare the following definition,
>
> optional< either< isbn_10, isbn_13 > > parse_isbn_string( std::string );
>
> to the equivalent using the 'expected' wording,
>
> optional< expected< isbn_10, isbn_13 > > parse_isbn_string( std::string );
>

I think there is some misunderstanding and confusion between
Expected/Optional/Either. Indeed, I'm quite sure that Expected and
Either are completely different. Even if Expected seems to be a subset
of Either, because you can choose to return a (value,
exception/error) couple in Either, the behavior will be different. IMHO,
Expected is more useful because it adds a lot of semantics for this
particular use-case.

I'd say that if Expected is the brother of Optional, Either is the child
of Variant (because it's a subset without adding specific semantic).

To correct the example above, it should be:

optional< either< isbn_10, isbn_13 > > parse_isbn_string( std::string );

OR

expected< either< isbn_10, isbn_13 > > parse_isbn_string( std::string );

Depending on the design of parse_isbn_string – if it says or not why the
parsing failed.

I think Either could be useful in case it's massively used to avoid the
syntactic overhead of Variant.

Finally, the first argument of this Either library was the error/value
couple facilities, but now we know that Expected is quite better, does
Either is just syntactic sugar ? Or do you have other relevant use cases ?

Best regards,
Pierre Talbot


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