#include <iostream>
#include <string>
#include <memory>

class X {
public:
	explicit X(const std::string& name)
		: name_ptr(std::make_unique<std::string>(name)) {
		std::cout << "Construct X name= " << *name_ptr << '\n';
	}

	// non copyable
	X(const X& x) = delete;
	X& operator=(const X& x) = delete;

	void info() const {
		std::cout << "info() in X\n";
	}

	X(X&& x) {
		std::cout << "Move construct name = " << *(x.name_ptr) << '\n';
		name_ptr = std::move(x.name_ptr);
	}
	X& operator=(X&& x) {
		std::cout << "Move operator= name = " << *(x.name_ptr) << '\n';
		name_ptr = std::move(x.name_ptr);
		return *this;
	}
	~X() {
		std::cout << "Destruct name= ";
		if (name_ptr != nullptr) {
			std::cout << *name_ptr;
		} else { 
			std::cout << "nullptr";
		}
		std::cout << '\n';
	}
private:
	std::unique_ptr<std::string> name_ptr;
};

void foo(X&& my_x) {
	std::cout << "In foo()\n";
	my_x.info();
}

int main() {
	auto x1 = X("DNA Myszy");	
	auto x2 = std::move(x1);

	foo(std::move(x2));
	std::cout << "After foo()\n";
}
