#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;
}
CiNpbmNsdWRlIDxpb3N0cmVhbT4KdXNpbmcgc3RkOjpjb3V0Owp1c2luZyBzdGQ6OmNpbjsKdXNpbmcgc3RkOjplbmRsOwoKc3RydWN0IEJsb2IgewogIEJsb2IoKSA6IGkoMCkgeyBjb3V0IDw8ICJDICIgPDwgdGhpcyA8PCBlbmRsOyB9CiAgQmxvYihjb25zdCBCbG9iJiBvKSA6IGkoby5pKSB7IGNvdXQgPDwgImMgIiA8PCB0aGlzIDw8ICIgPC0gIiA8PCAmbyA8PCBlbmRsOyB9CiAgQmxvYihCbG9iJiYgbykgOiBpKG8uaSkgeyBjb3V0IDw8ICJtICIgPDwgdGhpcyA8PCAiIDwtICIgPDwgJm8gPDwgZW5kbDsgfQogIEJsb2ImIG9wZXJhdG9yID0oY29uc3QgQmxvYiYpIHsgY291dCA8PCAiPSIgPDwgZW5kbDsgcmV0dXJuICp0aGlzOyB9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