32 #include <type_traits> 33 #include <boost/variant.hpp> 42 template<
typename L,
typename R>
45 using Either_t = boost::variant<L, R>;
48 enum { LeftVal, RightVal };
50 static_assert (!std::is_same<L, R>::value,
"Types cannot be the same.");
67 template<
typename LPrime,
typename RPrime,
69 std::is_convertible<RPrime, R>::value>>
82 return This_.which () == LeftVal;
87 return This_.which () == RightVal;
93 throw std::runtime_error {
"Tried accessing Left for a Right Either" };
94 return boost::get<L> (This_);
100 throw std::runtime_error {
"Tried accessing Right for a Left Either" };
101 return boost::get<R> (This_);
131 template<
typename RNew>
149 template<
typename RNew>
157 return e1.This_ == e2.This_;
166 template<
typename L,
typename R,
typename F,
typename = ResultOf_t<F ()>>
174 template<
typename L,
typename R>
182 template<
template<
typename>
class Cont,
typename L,
typename R>
185 std::pair<Cont<L>, Cont<R>> result;
186 for (
const auto& either : eithers)
187 if (either.IsLeft ())
188 result.first.push_back (either.GetLeft ());
190 result.second.push_back (either.GetRight ());
195 template<
typename L,
typename R>
211 template<
typename L,
typename R>
225 template<
typename RP>
231 template<
typename AV>
237 return R_t::Left (f.
GetLeft ());
240 return R_t::Left (v.GetLeft ());
242 return R_t::Right (f.
GetRight () (v.GetRight ()));
246 template<
typename L,
typename R>
258 return R_t::Left (value.
GetLeft ());
static Either Right(const R &r)
friend bool operator!=(const Either &e1, const Either &e2)
friend bool operator==(const Either &e1, const Either &e2)
static BindResult_t< F > Bind(const Either< L, R > &value, const F &f)
static Either< L, RP > Pure(const RP &v)
typename std::result_of< T >::type ResultOf_t
static Either Left(const L &l)
ResultOf_t< F(R)> BindResult_t
const R & GetRight() const
typename std::enable_if< B, T >::type EnableIf_t
R RightOr(const Either< L, R > &either, F &&f)
const L & GetLeft() const
boost::optional< L > MaybeLeft() const
static FmapResult_t< F > Apply(const Either< L, R > &either, const F &f)
static EnableIf_t<!std::is_convertible< RNew, R >::value, Either< L, RNew > > Right(const RNew &r)
boost::optional< R > MaybeRight() const
Either & operator=(const Either &)=default
boost::variant< L, R > AsVariant() const
std::pair< Cont< L >, Cont< R > > PartitionEithers(const Cont< Either< L, R >> &eithers)
static GSLResult_t< Type_t, AV > GSL(const Type_t &f, const AV &v)
typename InstanceApplicative< AF >::template GSLResult< AV >::Type_t GSLResult_t
static Either< L, RNew > FromMaybe(const boost::optional< RNew > &maybeRight, const L &left)
Either(const Either< LPrime, RPrime > &other)