fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class A {
  5. public:
  6. int x;
  7.  
  8. A(int x = 0) : x(x) {}
  9.  
  10. struct Cmp {
  11. const A *ptr;
  12. mutable bool val;
  13.  
  14. operator bool() const {
  15. return val;
  16. }
  17.  
  18. const Cmp &operator == (const A &other) const {
  19. return other == *this;
  20. }
  21. };
  22.  
  23. bool isEqualTo (const A &other) const {
  24. return x == other.x;
  25. }
  26.  
  27. Cmp operator == (const A &other) const {
  28. return {this, isEqualTo(other)};
  29. }
  30.  
  31. const Cmp &operator == (const Cmp &other) const {
  32. //other.val = other.val && (*this == *other.ptr).val;
  33. other.val &= other.ptr->isEqualTo(*this);
  34. return other;
  35. }
  36. };
  37.  
  38. int main() {
  39. cout << (A(10) == A(10) == A(10)) << endl;
  40. cout << (A(10) == A(9) == A(10)) << endl;
  41.  
  42. return 0;
  43. }
Success #stdin #stdout 0s 3412KB
stdin
Standard input is empty
stdout
1
0