// File: iZhangHui[P]CppPrimer/CH12_DynamicMemory/examples/release.cc
// Function: main
int main()
{
	unique_ptr<string> p1(new string("Stegosaurus"));

	// transfers ownership from p1
	// (which points to the string Stegosaurus) to p2
	unique_ptr<string> p2(p1.release()); // release makes p1 null
	cout << *p2 << endl; // prints Stegosaurus

	unique_ptr<string> p3(new string("Trex"));

	// reset deletes the memory to which p2 had pointed
	// and transfers ownership from p3 to p2
	p2.reset(p3.release());
	cout << *p2 << endl; // prints Trex

	// p1 is null, p2 is steg, and p3 is trex
	if (p1)
		cout << "p1 not null?" << endl;
	if (p3)
		cout << "p2 not null?" << endl;
	cout << *p2 << endl;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movl $0x0, -0x4(%rbp)
movl $0x20, %edi
callq 0x1090
movq %rax, -0x50(%rbp)
movq %rax, -0x58(%rbp)
movb $0x1, -0x25(%rbp)
leaq -0x11(%rbp), %rdi
movq %rdi, -0x48(%rbp)
callq 0x1100
movq -0x50(%rbp), %rdi
movq -0x48(%rbp), %rdx
leaq 0xd70(%rip), %rsi       # 0x2004
callq 0x10d0
jmp 0x129b
movq -0x58(%rbp), %rsi
movb $0x0, -0x25(%rbp)
leaq -0x10(%rbp), %rdi
movq %rdi, -0x70(%rbp)
callq 0x1570
leaq -0x11(%rbp), %rdi
callq 0x10c0
movq -0x70(%rbp), %rdi
callq 0x15a0
movq %rax, %rsi
leaq -0x30(%rbp), %rdi
movq %rdi, -0x68(%rbp)
callq 0x1570
movq -0x68(%rbp), %rdi
callq 0x15c0
movq %rax, -0x60(%rbp)
jmp 0x12e1
movq -0x60(%rbp), %rsi
movq 0x2cec(%rip), %rdi      # 0x3fd8
callq 0x1070
movq %rax, -0x78(%rbp)
jmp 0x12f7
movq -0x78(%rbp), %rdi
movq 0x2cc6(%rip), %rsi      # 0x3fc8
callq 0x10b0
jmp 0x1309
movl $0x20, %edi
callq 0x1090
movq %rax, -0x80(%rbp)
jmp 0x1319
movb $0x1, -0x3a(%rbp)
leaq -0x39(%rbp), %rdi
movq %rdi, -0x88(%rbp)
callq 0x1100
movq -0x80(%rbp), %rdi
movq -0x88(%rbp), %rdx
leaq 0xcd1(%rip), %rsi       # 0x2010
callq 0x10d0
jmp 0x1346
movq -0x80(%rbp), %rsi
movb $0x0, -0x3a(%rbp)
leaq -0x38(%rbp), %rdi
movq %rdi, -0xa0(%rbp)
callq 0x1570
leaq -0x39(%rbp), %rdi
callq 0x10c0
movq -0xa0(%rbp), %rdi
callq 0x15a0
movq %rax, %rsi
leaq -0x30(%rbp), %rdi
movq %rdi, -0x98(%rbp)
callq 0x15f0
movq -0x98(%rbp), %rdi
callq 0x15c0
movq %rax, -0x90(%rbp)
jmp 0x139b
movq -0x90(%rbp), %rsi
movq 0x2c2f(%rip), %rdi      # 0x3fd8
callq 0x1070
movq %rax, -0xa8(%rbp)
jmp 0x13b7
movq -0xa8(%rbp), %rdi
movq 0x2c03(%rip), %rsi      # 0x3fc8
callq 0x10b0
jmp 0x13cc
leaq -0x10(%rbp), %rdi
callq 0x1620
testb $0x1, %al
jne 0x13de
jmp 0x149f
movq 0x2bf3(%rip), %rdi      # 0x3fd8
leaq 0xc29(%rip), %rsi       # 0x2015
callq 0x1080
movq %rax, -0xb0(%rbp)
jmp 0x13fa
movq -0xb0(%rbp), %rdi
movq 0x2bc0(%rip), %rsi      # 0x3fc8
callq 0x10b0
jmp 0x140f
jmp 0x149f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x11(%rbp), %rdi
callq 0x10c0
testb $0x1, -0x25(%rbp)
jne 0x1431
jmp 0x143f
movq -0x58(%rbp), %rdi
movl $0x20, %esi
callq 0x10a0
jmp 0x155d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x154b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x39(%rbp), %rdi
callq 0x10c0
testb $0x1, -0x3a(%rbp)
jne 0x1472
jmp 0x1480
movq -0x80(%rbp), %rdi
movl $0x20, %esi
callq 0x10a0
jmp 0x154b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x1650
jmp 0x154b
leaq -0x38(%rbp), %rdi
callq 0x1620
testb $0x1, %al
jne 0x14ae
jmp 0x14e1
movq 0x2b23(%rip), %rdi      # 0x3fd8
leaq 0xb66(%rip), %rsi       # 0x2022
callq 0x1080
movq %rax, -0xb8(%rbp)
jmp 0x14ca
movq -0xb8(%rbp), %rdi
movq 0x2af0(%rip), %rsi      # 0x3fc8
callq 0x10b0
jmp 0x14df
jmp 0x14e1
leaq -0x30(%rbp), %rdi
callq 0x15c0
movq %rax, -0xc0(%rbp)
jmp 0x14f3
movq -0xc0(%rbp), %rsi
movq 0x2ad7(%rip), %rdi      # 0x3fd8
callq 0x1070
movq %rax, -0xc8(%rbp)
jmp 0x150f
movq -0xc8(%rbp), %rdi
movq 0x2aab(%rip), %rsi      # 0x3fc8
callq 0x10b0
jmp 0x1524
leaq -0x38(%rbp), %rdi
callq 0x1650
leaq -0x30(%rbp), %rdi
callq 0x1650
leaq -0x10(%rbp), %rdi
callq 0x1650
movl -0x4(%rbp), %eax
addq $0xd0, %rsp
popq %rbp
retq
leaq -0x30(%rbp), %rdi
callq 0x1650
leaq -0x10(%rbp), %rdi
callq 0x1650
movq -0x20(%rbp), %rdi
callq 0x10f0
nopw %cs:(%rax,%rax)