Is it possible to define some kind of template that can create a common comparable operator for structures?
For example, is something like this possible?
struct A { int one; int two; int three; }; bool AreEqual() { A a {1,2,3}; A b {1,2,3}; return ComparableStruct<A>(a) == ComparableStruct<A>(b); }
All this makes the field a field mapping of structures. You can assume that all fields have basic types or have an overloaded operator ==.
I have many such structures, and this will save me a lot of time if I can just put it in a template or something for comparison, and not define the == operator for each individual structure. Thanks!
Update
This seems to be impossible with C ++. I wonder why this is rejected from C ++ suggestions, if anyone has a reason, let us know!
For a solution that works with basic types, only see the solution from R Sahu.
source share