32 template<
typename L,
typename R>
35 std::expected<R, L> This_;
41 : This_ { std::move (ex) }
48 : This_ { std::move (r) }
58 : This_ { std::unexpect, l }
62 explicit Either (
const L& l)
requires (!std::is_same_v<L, R>)
63 : This_ { std::unexpect, l }
68 : This_ { std::unexpect, std::move (left.Value_) }
73 requires std::is_constructible_v<L, LL&&>
75 : This_ { std::unexpect, L { std::move (left.Value_) } }
91 return This_.has_value ();
97 throw std::runtime_error {
"Tried accessing Left for a Right Either" };
98 return This_.error ();
104 throw std::runtime_error {
"Tried accessing Left for a Right Either" };
105 return This_.error ();
111 throw std::runtime_error {
"Tried accessing Right for a Left Either" };
112 return This_.value ();
118 throw std::runtime_error {
"Tried accessing Right for a Left Either" };
119 return This_.value ();
146 return Result {
FromStdExpected, This_.transform_error (std::forward<F> (f)) };
153 return Result { This_.transform (std::forward<F> (f)) };
158 return e1.This_ == e2.This_;
167 template<
typename L,
typename R>
170 if (variant.index () == 0)
171 return std::get<0> (variant);
172 return Left<L> { std::get<1> (variant) };
175 template<
template<
typename>
class Cont,
typename L,
typename R>
178 std::pair<Cont<L>, Cont<R>> result;
179 for (
const auto& either : eithers)
180 if (either.IsLeft ())
181 result.first.push_back (either.GetLeft ());
183 result.second.push_back (either.GetRight ());
188 template<
typename Left,
typename Right,
typename... Args>
191 Overloaded visitor { std::forward<Args> (args)... };
193 std::move (visitor) (either.
GetRight ()) :
194 std::move (visitor) (either.
GetLeft ());
197 template<
typename Left,
typename Right,
typename... Args>
200 Overloaded visitor { std::forward<Args> (args)... };
201 return either.IsRight () ?
202 std::move (visitor) (std::move (either.GetRight ())) :
203 std::move (visitor) (std::move (either.GetLeft ()));
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
Either(Left< LL > &&left)
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
Either< L, R > EitherFromSwapped(const std::variant< R, L > &variant)
auto Visit(const Either< Left, Right > &either, Args &&... args)
std::pair< Cont< L >, Cont< R > > Partition(const Cont< Either< L, R > > &eithers)