11 Classes [class]

11.10 Comparisons [class.compare]

11.10.2 Equality operators [class.eq]

A defaulted equality operator ([expr.eq]) function shall have a declared return type bool.
A defaulted == operator function for a class C is defined as deleted unless, for each in the expanded list of subobjects for an object x of type C, is a valid expression and contextually convertible to bool.
The return value V of a defaulted == operator function with parameters x and y is determined by comparing corresponding elements and in the expanded lists of subobjects for x and y (in increasing index order) until the first index i where yields a result value which, when contextually converted to bool, yields false.
If no such index exists, V is true.
Otherwise, V is false.
A defaulted != operator function for a class C with parameters x and y is defined as deleted if
  • overload resolution ([over.match]), as applied to x == y (also considering synthesized candidates with reversed order of parameters ([over.match.oper])), results in an ambiguity or a function that is deleted or inaccessible from the operator function, or
  • x == y cannot be contextually converted to bool.
Otherwise, the operator function yields (x == y) ? false : true.
struct D {
  int i;
  friend bool operator==(const D& x, const D& y) = default;
                                                // OK, returns x.i == y.i
  bool operator!=(const D& z) const = default;  // OK, returns (*this == z) ? false : true
end example