#include <iostream>
#include <utility>
using namespace std;
struct foo {
explicit foo(char const* s) : m_str(s) { cout << "init " << m_str << "\n"; }
foo(foo const& other) : m_str(other.m_str) { cout << "copy " << m_str << "\n"; }
foo(foo&& other) : m_str(other.m_str) { cout << "move " << m_str << "\n"; }
~foo() { cout << "destroy " << m_str << "\n"; }
foo& operator = (foo const& other) { m_str = other.m_str; cout << "copy-assign " << m_str << "\n"; return *this; }
foo& operator = (foo&& other) { m_str = other.m_str; cout << "move-assign " << m_str << "\n"; return *this; }
private:
char const* m_str;
};
foo good() { return foo("good"); }
foo const bad() { return foo("bad"); }
void consume(foo) { }
template <class T> void consume2(T&& t) {
consume(forward<T>(t));
}
int main()
{
consume2(good());
cout << "\n";
consume2(bad());
// cout << "\n";
// good() = foo("nicht so gut");
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dXRpbGl0eT4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgpzdHJ1Y3QgZm9vIHsKCWV4cGxpY2l0IGZvbyhjaGFyIGNvbnN0KiBzKSA6IG1fc3RyKHMpIHsgY291dCA8PCAiaW5pdCAiIDw8IG1fc3RyIDw8ICJcbiI7IH0KCWZvbyhmb28gY29uc3QmIG90aGVyKSAgOiBtX3N0cihvdGhlci5tX3N0cikgeyBjb3V0IDw8ICJjb3B5ICIgPDwgbV9zdHIgPDwgIlxuIjsgfQoJZm9vKGZvbyYmIG90aGVyKSA6IG1fc3RyKG90aGVyLm1fc3RyKSB7IGNvdXQgPDwgIm1vdmUgIiA8PCBtX3N0ciA8PCAiXG4iOyB9Cgl+Zm9vKCkgeyBjb3V0IDw8ICJkZXN0cm95ICIgPDwgbV9zdHIgPDwgIlxuIjsgfQoKCWZvbyYgb3BlcmF0b3IgPSAoZm9vIGNvbnN0JiBvdGhlcikgeyBtX3N0ciA9IG90aGVyLm1fc3RyOyBjb3V0IDw8ICJjb3B5LWFzc2lnbiAiIDw8IG1fc3RyIDw8ICJcbiI7IHJldHVybiA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