To clarify from my comment, this will support code so you can either provide all variations of operators:
inline bool operator==(const MyClass& lhs, const MyClass& rhs) {
return lhs.middle == rhs.middle;
}
inline bool operator==(const int& lhs, const MyClass& rhs) {
return lhs == rhs.middle;
}
inline bool operator==(const MyClass& lhs, const int& rhs) {
return lhs.middle == rhs;
}
And do that for every operator (which blows up into a significant amount of code). OR if it makes sense to, you can provide a constructor which constructs from int:
struct MyClass {
MyClass() {} // default
MyClass( int x ) { /* init for an int here */ }
int start;
int middle;
int threequarters;
};
If you do this, then you will only need the MyClass,MyClass version for each operator:
inline bool operator==(const MyClass& lhs, const MyClass& rhs) {
return lhs.middle == rhs.middle;
}
Because when the compiler sees:
if ( 5 == my_class ) {}
It actually does this:
if ( MyClass(5).operator==( my_class ) ) {}