#include <iostream>
using namespace std;

class A {
public:
    int x;

    A(int x = 0) : x(x) {}

    struct Cmp {
        const A *ptr;
        mutable bool val;

        operator bool() const {
            return val;
        }

        const Cmp &operator == (const A &other) const {
            return other == *this;
        }
    };
    
    bool isEqualTo (const A &other) const {
    	return x == other.x;
    }

    Cmp operator == (const A &other) const {        
        return {this, isEqualTo(other)};
    }

    const Cmp &operator == (const Cmp &other) const {
        //other.val = other.val && (*this == *other.ptr).val;
        other.val &= other.ptr->isEqualTo(*this);
        return other;
    }
};

int main() {
    cout << (A(10) == A(10) == A(10)) << endl;
    cout << (A(10) == A(9) == A(10)) << endl;

    return 0;
}