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
As a slight aside, the nicest way I know of writing equality operators for classes with lots of members uses this idea (this code requires C++ 14):
#include
struct foo
{
int x = 1;
double y = 42.0;
char z = 'z';
auto
members() const
{
return std::tie(x, y, z);
}
};
inline bool
operator==(const foo& lhs, const foo& rhs)
{
return lhs.members() == rhs.members();
}
int
main()
{
foo f1;
foo f2;
return f1 == f2;
}
Code on Compiler Explorer