#include <iostream>
using namespace std;

class Foo {
    enum OpState {
    	None ,
    	PlusState ,
    	NotState ,
    };

public:
    friend Foo& operator+(Foo& lhs, const Foo& rhs) {
		cout << "operator+(Foo& lhs, const Foo& rhs)" << endl;
		if(lhs.opState == NotState) {
		    return lhs.operatorexclamativeplus(rhs);
		}
		return lhs;
	}

   Foo& operator+() {
   	   cout << "operator+()" << endl;
       opState = PlusState;
       return *this;
   }
   Foo& operator!() {
   	   cout << "operator!()" << endl;
       switch(opState) {
       case PlusState:
           operatorexclamativeplus();
           opState = None;
           break;       
       default:
           opState = NotState;
           break;       
       }
       return *this;
   }

private:
    void operatorexclamativeplus() {
   	   cout << "operatorexclamativeplus()" << endl;
    }
    Foo& operatorexclamativeplus(const Foo& rhs) {
   	   cout << "operatorexclamativeplus(const Foo& rhs)" << endl;
   	   return *this;
    }

    OpState opState;
};


int main() {
	Foo x;
	Foo y;
	!+x;
	Foo z = y !+ x;
	return 0;
}