
#include <iostream>
using std::cout;
using std::cin;
using std::endl;

struct Blob {
  Blob() : i(0) { cout << "C " << this << endl; }
  Blob(const Blob& o) : i(o.i) { cout << "c " << this << " <- " << &o << endl; }
  Blob(Blob&& o) : i(o.i) { cout << "m " << this << " <- " << &o << endl; }
  Blob& operator =(const Blob&) { cout << "=" << endl; return *this; }
  Blob& operator =(Blob&&) { cout << "=m" << endl; return *this; }
  ~Blob() { cout << "~ " << this << endl; }

  int i;
};

int main() {
  try {
     cout << "Throw directly: " << endl;
     throw Blob();
  } catch(const Blob& b) { cout << "caught: " << &b << endl; }
  try {
     cout << "Throw with object about to die anyhow" << endl;
     Blob b;
     throw b;
  } catch(const Blob& b) { cout << "caught: " << &b << endl; }
  cout << "Throw with object not about to die anyhow (enter non-zero integer)" << endl;
  Blob b;
  int tmp = 0;
  cin >> tmp; //Just trying to keep optimizers from removing dead code
  try {
    if(tmp) throw b;
    cout << "Test is worthless if you enter '0' silly" << endl;
  } catch(const Blob& bb) { cout << "caught: " << &bb << endl; }
  b.i = tmp;
  cout << b.i << endl;
}