I would try to think if there is a 'natural' way to transform that proposal so that the operators are not necessarily defined as member functions. While member functions map more naturally to the current uses of ' = default', free function operators are more natural to use, allowing the same conversions on both arguments. With the current wording, this code would fail to compile:
struct T {
int value;
T(int v) : value(v) {} // implicit!
bool operator==(T const &) = default;
};
int main() {
return 1 == T(1);
}
While if we swap the order of the equality check it would compile. I find that asymmetry slightly disturbing. Maybe we could consider extending ' = default' to anything that is defined inside the class definition and allow:
struct T {
// ...
friend bool operator==(T const&, T const&) = default;
};
Additionally, I would like to have the wording explicitly mention that the operators can only be defaulted when they apply to exactly the same type that is being defined.
I have the feeling that I really want something more like:
struct T {
operator== = default;
};
Or some other mechanism by which the type is not present in the signature and thus removes the potential for attempts to default cross-type comparisons... But this would require mayor changes in the grammar and is better avoided.
David