Skip to content

Commit

Permalink
Add operator== to TaggedUnion.hpp
Browse files Browse the repository at this point in the history
Following @liuzicheng1987 advice (#272 (comment)), I had a hard time converting my code in order to have it work in TaggedUnion.hpp.

Note sure at all that it is OK?
  • Loading branch information
ttamttam authored Nov 24, 2024
1 parent 5f9d0c1 commit aeac689
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions include/rfl/TaggedUnion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,27 @@ struct PossibleTags<TaggedUnion<_discriminator, Ts...>> {
template <class T>
using possible_tags_t = typename PossibleTags<T>::Type;

template <internal::StringLiteral _discriminator, class... Ts>
bool operator==(
const TaggedUnion<_discriminator, Ts...>& lhs,
const TaggedUnion<_discriminator, Ts...>& rhs
) {

return (lhs.variant().index() == rhs.variant().index()) &&
lhs.variant().visit(
[&rhs](const auto& l) {
return rhs.variant().visit(
[&l](const auto& r) -> bool {
if constexpr (std::is_same_v<std::decay_t<decltype(l)>, std::decay_t<decltype(r)>>)
return l == r;
else
return false;
}
);
}
);
}

} // namespace rfl

#endif // RFL_TAGGEDUNION_HPP_

0 comments on commit aeac689

Please sign in to comment.