types/tagged: add an equality operator

This commit is contained in:
Danny Robson 2020-07-21 15:05:21 +10:00
parent 47d0e69b46
commit 1550529a39

View File

@ -201,4 +201,24 @@ namespace cruft {
arg arg
); );
} }
template <typename ...ComponentsT>
bool operator== (tagged<ComponentsT...> const &lhs, tagged<ComponentsT...> const &rhs)
{
// Check the tags actually match to start with. This lets us use
// short-circuiting in a second for the actual equality check.
if (lhs.tag () != rhs.tag ())
return false;
// Construct a fold-expression that tests every component type for
// equality. Use short-circuiting with `is` to protect against `get`
// queries for the wrong types.
return (
(
lhs.template is<ComponentsT> () &&
(lhs.template get<ComponentsT> () == rhs.template get<ComponentsT> ())
) || ...
);
}
} }