diff --git a/types/tagged.hpp b/types/tagged.hpp index 9bf7b9fb..f85a19f6 100644 --- a/types/tagged.hpp +++ b/types/tagged.hpp @@ -201,4 +201,24 @@ namespace cruft { arg ); } + + + template + bool operator== (tagged const &lhs, tagged 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 () && + (lhs.template get () == rhs.template get ()) + ) || ... + ); + } }