#include <iostream>
#include <iomanip>
using namespace std;
class Test {
public:
Test() { cout << "Test()\n"; }
Test(int x):val_(x){ cout << "Test(" << x << ")\n"; }
Test(const Test& t):val_(t.val_) { cout << "Test(const Test& " << t.val_ << ")\n"; }
Test(Test&&t) :val_(t.val_) { cout << "Test(const Test&& " << t.val_ << ")\n"; t.val_ = 0; }
Test& operator = (const Test& t) {
cout << "Test& operator = (const Test& " << t.val_ <<")\n";
val_ = t.val_;
return *this;}
Test& operator = (Test&& t) {
cout << "Test& operator = (const Test&&" << t.val_ <<")\n";
val_ = t.val_; t.val_ = 0;
return *this;}
~Test() { cout << "~Test(" << val_ <<")\n"; }
int val() const { return val_; }
private:
int val_ = 0;
};
struct Quest
{
Test t;
Quest(Test&& t):t(t){}
};
struct Qwest
{
Test t;
Qwest(Test&& t):t(move(t)){}
};
int main(int argc, const char * argv[])
{
Test t(5), s(6);
Quest q(move(t));
Qwest w(move(s));
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8aW9tYW5pcD4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgpjbGFzcyBUZXN0IHsKcHVibGljOgogICAgVGVzdCgpICAgICAgICAgICAgIHsgY291dCA8PCAiVGVzdCgpXG4iOyB9CiAgICBUZXN0KGludCB4KTp2YWxfKHgpeyBjb3V0IDw8ICJUZXN0KCIgPDwgeCA8PCAiKVxuIjsgfQogICAgVGVzdChjb25zdCBUZXN0JiB0KTp2YWxfKHQudmFsXykgeyBjb3V0IDw8ICJUZXN0KGNvbnN0IFRlc3QmICIgPDwgdC52YWxfIDw8ICIpXG4iOyB9CiAgICBUZXN0KFRlc3QmJnQpICAgICAgOnZhbF8odC52YWxfKSB7IGNvdXQgPDwgIlRlc3QoY29uc3QgVGVzdCYmICIgPDwgdC52YWxfIDw8ICIpXG4iOyB0LnZhbF8gPSAwOyB9CiAgICBUZXN0JiBvcGVyYXRvciA9IChjb25zdCBUZXN0JiB0KSAgewogICAgICAgIGNvdXQgPDwg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