Skip to content

Commit

Permalink
add Either::operator<< to support debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
ksedgwic committed Aug 8, 2024
1 parent c6fa49f commit 188accf
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Util/Either.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define UTIL_EITHER_HPP

#include<cstdint>
#include<iostream>
#include<utility>

namespace Util {
Expand Down Expand Up @@ -225,6 +226,19 @@ bool operator<=(Util::Either<L,R> const& a, Util::Either<L,R> const& b) {
return !(b < a);
}

template<typename L, typename R>
std::ostream& operator<<(std::ostream& os, const Either<L, R>& either) {
either.cmatch(
[&](const L& l) {
os << "Left(" << l << ")";
},
[&](const R& r) {
os << "Right(" << r << ")";
}
);
return os;
}

} // namespace Util

#endif /* !defined(UTIL_EITHER_HPP) */

0 comments on commit 188accf

Please sign in to comment.