31 template<
typename L,
typename R>
34 std::expected<R, L> This_;
40 : This_ { std::move (ex) }
47 : This_ { std::move (r) }
57 : This_ { std::unexpect, l }
61 explicit Either (
const L& l)
requires (!std::is_same_v<L, R>)
62 : This_ { std::unexpect, l }
67 : This_ { std::unexpect, std::move (left.Value_) }
72 requires std::is_constructible_v<L, LL&&>
74 : This_ { std::unexpect, L { std::move (left.Value_) } }
90 return This_.has_value ();
96 throw std::runtime_error {
"Tried accessing Left for a Right Either" };
97 return This_.error ();
103 throw std::runtime_error {
"Tried accessing Left for a Right Either" };
104 return This_.error ();
110 throw std::runtime_error {
"Tried accessing Right for a Left Either" };
111 return This_.value ();
117 throw std::runtime_error {
"Tried accessing Right for a Left Either" };
118 return This_.value ();
145 return Result {
FromStdExpected, This_.transform_error (std::forward<F> (f)) };
152 return Result { This_.transform (std::forward<F> (f)) };
157 return e1.This_ == e2.This_;
166 template<
template<
typename>
class Cont,
typename L,
typename R>
169 std::pair<Cont<L>, Cont<R>> result;
170 for (
const auto& either : eithers)
171 if (either.IsLeft ())
172 result.first.push_back (either.GetLeft ());
174 result.second.push_back (either.GetRight ());
179 template<
typename Left,
typename Right,
typename... Args>
182 Overloaded visitor { std::forward<Args> (args)... };
184 std::move (visitor) (either.
GetRight ()) :
185 std::move (visitor) (either.
GetLeft ());
188 template<
typename Left,
typename Right,
typename... Args>
191 Overloaded visitor { std::forward<Args> (args)... };
192 return either.IsRight () ?
193 std::move (visitor) (std::move (either.GetRight ())) :
194 std::move (visitor) (std::move (either.GetLeft ()));
Either(Left< LL > &&left)
friend bool operator!=(const Either &e1, const Either &e2)
Either(Left< void >, const L &l)
Either(Either &&)=default
std::optional< L > MaybeLeft() const
Either(FromStdExpected_t, std::expected< R, L > &&ex)
Either & operator=(const Either &)=default
const L & GetLeft() const
std::optional< R > MaybeRight() const
friend bool operator==(const Either &e1, const Either &e2)
auto MapLeft(F &&f) const
auto MapRight(F &&f) const
const R & GetRight() const
Either(const Either &)=default
struct LC::Util::FromStdExpected_t FromStdExpected
auto Visit(const Either< Left, Right > &either, Args &&... args)
std::pair< Cont< L >, Cont< R > > Partition(const Cont< Either< L, R > > &eithers)