// File: /workspace/github_cpp_makefile_star2_O2/iZhangHui[P]CppPrimer/CH16_TemplatesAndGenericProgramming/exercises/ex16_30_31.cc
// Function: main
int main(int argc, char const *argv[])
{
	Blob<int> blob{1, 2, 3};
	blob.push_back(4);

	for (size_t i = 0; i != blob.size(); ++i) {
		std::cout << blob[i] << " ";
	}
	std::cout << std::endl;

	// int ret = blob.back();
	int& ret = blob.back();
	ret = 5;

	for (size_t i = 0; i != blob.size(); ++i) {
		std::cout << blob[i] << " ";
	}
	std::cout << std::endl;

	Blob<std::string> b1; // empty Blob
	std::cout << b1.size() << std::endl;
	{  // new scope
		Blob<std::string> b2 = {"a", "an", "the"};
		b1 = b2;  // b1 and b2 share the same elements
		b2.push_back("about");
		std::cout << b1.size() << " " << b2.size() << std::endl;
	} // b2 is destroyed, but the elements it points to must not be destroyed
	std::cout << b1.size() << std::endl;

	for (size_t i = 0; i != b1.size(); ++i) {
		std::cout << b1[i] << " ";
	}
	std::cout << std::endl;

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x100, %rsp            # imm = 0x100
movabsq $0x200000001, %rax      # imm = 0x200000001
leaq -0xe8(%rbp), %rbx
movq %rax, (%rbx)
movl $0x3, 0x8(%rbx)
leaq -0x88(%rbp), %r14
pushq $0x3
popq %rdx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x26be
movl $0x4, (%rbx)
movq (%r14), %rdi
leaq -0xe8(%rbp), %rsi
callq 0x2e4c
xorl %ebx, %ebx
movq 0x4c4c(%rip), %r15      # 0x6fc8
leaq 0x1c81(%rip), %r12      # 0x4004
movq -0x88(%rbp), %rax
movq 0x8(%rax), %rcx
subq (%rax), %rcx
sarq $0x2, %rcx
cmpq %rcx, %rbx
je 0x23bf
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2762
movl (%rax), %esi
movq %r15, %rdi
callq 0x21c0
movq %rax, %rdi
movq %r12, %rsi
callq 0x2110
incq %rbx
jmp 0x2383
movq 0x4c02(%rip), %rdi      # 0x6fc8
callq 0x2090
leaq -0x88(%rbp), %rdi
callq 0x27d0
movl $0x5, (%rax)
xorl %ebx, %ebx
leaq -0x88(%rbp), %r14
movq 0x4bdb(%rip), %r15      # 0x6fc8
leaq 0x1c10(%rip), %r12      # 0x4004
movq -0x88(%rbp), %rax
movq 0x8(%rax), %rcx
subq (%rax), %rcx
sarq $0x2, %rcx
cmpq %rcx, %rbx
je 0x2430
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2762
movl (%rax), %esi
movq %r15, %rdi
callq 0x21c0
movq %rax, %rdi
movq %r12, %rsi
callq 0x2110
incq %rbx
jmp 0x23f4
movq 0x4b91(%rip), %rdi      # 0x6fc8
callq 0x2090
leaq -0x58(%rbp), %rdi
callq 0x2834
movq -0x58(%rbp), %rax
movq 0x8(%rax), %rsi
subq (%rax), %rsi
sarq $0x5, %rsi
movq 0x4b6d(%rip), %rdi      # 0x6fc8
callq 0x20c0
movq %rax, %rdi
callq 0x2090
leaq 0x1b97(%rip), %rsi      # 0x4006
leaq -0xe8(%rbp), %r14
leaq -0x21(%rbp), %rdx
movq %r14, %rdi
callq 0x2060
leaq -0xc8(%rbp), %r15
leaq 0x1b78(%rip), %rsi      # 0x4008
leaq -0x23(%rbp), %rdx
movq %r15, %rdi
callq 0x2060
leaq -0xa8(%rbp), %r15
leaq 0x1b61(%rip), %rsi      # 0x400b
leaq -0x22(%rbp), %rdx
movq %r15, %rdi
callq 0x2060
leaq -0x118(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
pushq $0x3
popq %rdx
callq 0x28ac
pushq $0x40
popq %rbx
leaq (%rbx,%rbp), %rdi
addq $-0xe8, %rdi
callq 0x2080
addq $-0x20, %rbx
cmpq $-0x20, %rbx
jne 0x24cf
leaq -0x58(%rbp), %rdi
leaq -0x118(%rbp), %rsi
callq 0x29be
leaq 0x1b0f(%rip), %rsi      # 0x400f
leaq -0xe8(%rbp), %rdi
leaq -0x21(%rbp), %rdx
callq 0x2060
movq -0x118(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
callq 0x3290
leaq -0xe8(%rbp), %rdi
callq 0x2080
movq -0x58(%rbp), %rax
movq 0x8(%rax), %rsi
subq (%rax), %rsi
sarq $0x5, %rsi
movq 0x4a83(%rip), %rdi      # 0x6fc8
callq 0x20c0
leaq 0x1ab3(%rip), %rsi      # 0x4004
movq %rax, %rdi
callq 0x2110
movq -0x118(%rbp), %rcx
movq 0x8(%rcx), %rsi
subq (%rcx), %rsi
sarq $0x5, %rsi
movq %rax, %rdi
callq 0x20c0
movq %rax, %rdi
callq 0x2090
leaq -0x118(%rbp), %rdi
callq 0x2b1a
movq -0x58(%rbp), %rax
movq 0x8(%rax), %rsi
subq (%rax), %rsi
sarq $0x5, %rsi
movq 0x4a2b(%rip), %rdi      # 0x6fc8
callq 0x20c0
movq %rax, %rdi
callq 0x2090
xorl %ebx, %ebx
leaq -0x58(%rbp), %r14
movq 0x4a11(%rip), %r15      # 0x6fc8
leaq 0x1a46(%rip), %r12      # 0x4004
movq -0x58(%rbp), %rax
movq 0x8(%rax), %rcx
subq (%rax), %rcx
sarq $0x5, %rcx
cmpq %rcx, %rbx
je 0x25f8
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2950
movq %r15, %rdi
movq %rax, %rsi
callq 0x2100
movq %rax, %rdi
movq %r12, %rsi
callq 0x2110
incq %rbx
jmp 0x25be
movq 0x49c9(%rip), %rdi      # 0x6fc8
callq 0x2090
leaq -0x58(%rbp), %rdi
callq 0x2b1a
leaq -0x88(%rbp), %rdi
callq 0x2b42
xorl %eax, %eax
addq $0x100, %rsp            # imm = 0x100
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0xe8(%rbp), %rdi
callq 0x2080
jmp 0x2688
jmp 0x2685
movq %rax, %rbx
pushq $0x40
popq %r14
leaq (%r14,%rbp), %rdi
addq $-0xe8, %rdi
callq 0x2080
addq $-0x20, %r14
cmpq $-0x20, %r14
jne 0x2645
jmp 0x2699
jmp 0x2663
movq %rax, %rbx
addq $-0x20, %r15
movq %r15, %rdi
callq 0x2080
cmpq %r14, %r15
jne 0x2666
jmp 0x2699
jmp 0x2696
jmp 0x26a6
jmp 0x26a6
jmp 0x26a6
jmp 0x26a6
jmp 0x2696
movq %rax, %rbx
leaq -0x118(%rbp), %rdi
callq 0x2b1a
jmp 0x2699
movq %rax, %rbx
leaq -0x58(%rbp), %rdi
callq 0x2b1a
jmp 0x26a9
jmp 0x26a6
movq %rax, %rbx
leaq -0x88(%rbp), %rdi
callq 0x2b42
movq %rbx, %rdi
callq 0x21d0
nop