I came up with the idea to define a generic comparison operator which would work with any type, for the fun of it.
#include
#include
Doing this is indeed a terrible idea.
If some type does not define an equality operator, it is most likely because you cannot reasonably compare two objects of that type for equality.
Even for the case where the missing equality operator was an oversight by the implementer, any "catch-all" implementation you would come up with is highly unlikely to do something sensible.†
So to conclude: Don't do this! Compile time errors are better than runtime errors; instead of prematurely adding a most certainly broken "solution" hiding the actual problem, add actual solutions as the compile time errors occur.
†For starters, the solution you came up with fails for types with padding, types with overloaded unary operator&
, and any type that has some pointer or reference like member; or even types with any member or base of any of the aforementioned categories. So for a ton of stuff.