Boost logo

Boost :

Subject: Re: [boost] Interest in an 'either' library?
From: Larry Evans (cppljevans_at_[hidden])
Date: 2013-06-22 11:17:36


On 06/21/13 11:35, David Sankel wrote:
> **semantics**:
>
> template< typename left_type, typename right_type>
> struct either
> {
> // postcondition, is_left()
> either( left_type );
>
> // postcondition, is_right()
> either( right_type );
>
> bool is_left() const;
> bool is_right() const;
>
> // postcondition, is_left()
> either & operator=( left_type );
>
> // postcondition, is_right()
> either & operator=( right_type );
>
> // precondition, is_left()
> left_type left();
>
> // precondition, is_right()
> right_type right();
> private:
> };
>
> **uses**:
>
> **Use 1**: Can be used as an alternative to exceptions or the (error
> codes+set reference idiom):
>
> either<error_code, file_id> load_file(...);
>
> vs.
>
> error_code load_file( file_id &, ... );
>
> or
>
> // throws std::exception
> file_id load_file(...);
>
Isn't this like haskell's either:

http://www.haskell.org/ghc/docs/6.12.2/html/libraries/base-4.2.0.1/Data-Either.html

which also has been suggested as a semi-replacement for exceptions:

http://www.haskell.org/pipermail/haskell-cafe/2004-August/006549.html

which uses the terms expected and unexpected, which might explain the
name expected used in the proposed Boost.Expected library mentioned
in Bjorn Reese's reply.

I remember seeing elsewhere that haskell's either was mentioned as
a replacement for exceptions. I see if I can find it.

-regards,
Larry


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