// File: 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
subq $0x2d0, %rsp            # imm = 0x2D0
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x1, -0x5c(%rbp)
movl $0x2, -0x58(%rbp)
movl $0x3, -0x54(%rbp)
leaq -0x5c(%rbp), %rax
movq %rax, -0x50(%rbp)
movq $0x3, -0x48(%rbp)
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
leaq -0x40(%rbp), %rdi
movq %rdi, -0x1a0(%rbp)
callq 0x2af0
movq -0x1a0(%rbp), %rdi
movl $0x4, -0x60(%rbp)
leaq -0x60(%rbp), %rsi
callq 0x2c10
jmp 0x23bf
movq $0x0, -0x78(%rbp)
movq -0x78(%rbp), %rax
movq %rax, -0x1b0(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x2c40
movq %rax, -0x1a8(%rbp)
jmp 0x23e4
movq -0x1b0(%rbp), %rax
movq -0x1a8(%rbp), %rcx
cmpq %rcx, %rax
je 0x2464
movq -0x78(%rbp), %rsi
leaq -0x40(%rbp), %rdi
callq 0x2c70
movq %rax, -0x1b8(%rbp)
jmp 0x240d
movq -0x1b8(%rbp), %rax
movl (%rax), %esi
movq 0x8bab(%rip), %rdi      # 0xafc8
callq 0x21e0
movq %rax, -0x1c0(%rbp)
jmp 0x242b
movq -0x1c0(%rbp), %rdi
leaq 0x4bdb(%rip), %rsi      # 0x7014
callq 0x2120
jmp 0x2440
jmp 0x2442
movq -0x78(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x78(%rbp)
jmp 0x23c7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x2ad8
movq 0x8b5d(%rip), %rdi      # 0xafc8
movq 0x8b46(%rip), %rsi      # 0xafb8
callq 0x2150
jmp 0x2479
leaq -0x40(%rbp), %rdi
callq 0x2d30
movq %rax, -0x1c8(%rbp)
jmp 0x248b
movq -0x1c8(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rax
movl $0x5, (%rax)
movq $0x0, -0x88(%rbp)
movq -0x88(%rbp), %rax
movq %rax, -0x1d8(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x2c40
movq %rax, -0x1d0(%rbp)
jmp 0x24cb
movq -0x1d8(%rbp), %rax
movq -0x1d0(%rbp), %rcx
cmpq %rcx, %rax
je 0x2543
movq -0x88(%rbp), %rsi
leaq -0x40(%rbp), %rdi
callq 0x2c70
movq %rax, -0x1e0(%rbp)
jmp 0x24f7
movq -0x1e0(%rbp), %rax
movl (%rax), %esi
movq 0x8ac1(%rip), %rdi      # 0xafc8
callq 0x21e0
movq %rax, -0x1e8(%rbp)
jmp 0x2515
movq -0x1e8(%rbp), %rdi
leaq 0x4af1(%rip), %rsi      # 0x7014
callq 0x2120
jmp 0x252a
jmp 0x252c
movq -0x88(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x88(%rbp)
jmp 0x24ab
movq 0x8a7e(%rip), %rdi      # 0xafc8
movq 0x8a67(%rip), %rsi      # 0xafb8
callq 0x2150
jmp 0x2558
leaq -0xb8(%rbp), %rdi
callq 0x2de0
jmp 0x2566
leaq -0xb8(%rbp), %rdi
callq 0x2e70
movq %rax, -0x1f0(%rbp)
jmp 0x257b
movq -0x1f0(%rbp), %rsi
movq 0x8a3f(%rip), %rdi      # 0xafc8
callq 0x2030
movq %rax, -0x1f8(%rbp)
jmp 0x2597
movq -0x1f8(%rbp), %rdi
movq 0x8a13(%rip), %rsi      # 0xafb8
callq 0x2150
jmp 0x25ac
movb $0x1, -0x164(%rbp)
leaq -0x158(%rbp), %rax
movq %rax, -0x208(%rbp)
movq %rax, -0x160(%rbp)
leaq -0x161(%rbp), %rdi
movq %rdi, -0x200(%rbp)
callq 0x2200
movq -0x208(%rbp), %rdi
movq -0x200(%rbp), %rdx
leaq 0x4a26(%rip), %rsi      # 0x7016
callq 0x2170
jmp 0x25f7
leaq -0x138(%rbp), %rax
movq %rax, -0x218(%rbp)
movq %rax, -0x160(%rbp)
leaq -0x162(%rbp), %rdi
movq %rdi, -0x210(%rbp)
callq 0x2200
movq -0x218(%rbp), %rdi
movq -0x210(%rbp), %rdx
leaq 0x49e4(%rip), %rsi      # 0x7018
callq 0x2170
jmp 0x263b
leaq -0x118(%rbp), %rax
movq %rax, -0x228(%rbp)
movq %rax, -0x160(%rbp)
leaq -0x163(%rbp), %rdi
movq %rdi, -0x220(%rbp)
callq 0x2200
movq -0x228(%rbp), %rdi
movq -0x220(%rbp), %rdx
leaq 0x49a3(%rip), %rsi      # 0x701b
callq 0x2170
jmp 0x267f
movb $0x0, -0x164(%rbp)
leaq -0x158(%rbp), %rax
movq %rax, -0xf8(%rbp)
movq $0x3, -0xf0(%rbp)
movq -0xf8(%rbp), %rsi
movq -0xf0(%rbp), %rdx
leaq -0xe8(%rbp), %rdi
callq 0x2ea0
jmp 0x26bb
leaq -0x158(%rbp), %rax
movq %rax, -0x238(%rbp)
addq $0x60, %rax
movq %rax, -0x230(%rbp)
movq -0x230(%rbp), %rdi
addq $-0x20, %rdi
movq %rdi, -0x240(%rbp)
callq 0x20d0
movq -0x238(%rbp), %rcx
movq -0x240(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x230(%rbp)
jne 0x26d4
leaq -0x163(%rbp), %rdi
callq 0x2160
leaq -0x162(%rbp), %rdi
callq 0x2160
leaq -0x161(%rbp), %rdi
callq 0x2160
leaq -0xb8(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
callq 0x2fc0
jmp 0x273e
leaq -0x189(%rbp), %rdi
movq %rdi, -0x248(%rbp)
callq 0x2200
movq -0x248(%rbp), %rdx
leaq 0x48c0(%rip), %rsi      # 0x701f
leaq -0x188(%rbp), %rdi
callq 0x2170
jmp 0x276d
leaq -0xe8(%rbp), %rdi
leaq -0x188(%rbp), %rsi
callq 0x2ff0
jmp 0x2782
leaq -0x188(%rbp), %rdi
callq 0x20d0
leaq -0x189(%rbp), %rdi
callq 0x2160
leaq -0xb8(%rbp), %rdi
callq 0x2e70
movq %rax, -0x250(%rbp)
jmp 0x27af
movq -0x250(%rbp), %rsi
movq 0x880b(%rip), %rdi      # 0xafc8
callq 0x2030
movq %rax, -0x258(%rbp)
jmp 0x27cb
movq -0x258(%rbp), %rdi
leaq 0x483b(%rip), %rsi      # 0x7014
callq 0x2120
movq %rax, -0x260(%rbp)
jmp 0x27e7
leaq -0xe8(%rbp), %rdi
callq 0x2e70
movq %rax, -0x268(%rbp)
jmp 0x27fc
movq -0x268(%rbp), %rsi
movq -0x260(%rbp), %rdi
callq 0x2030
movq %rax, -0x270(%rbp)
jmp 0x2818
movq -0x270(%rbp), %rdi
movq 0x8792(%rip), %rsi      # 0xafb8
callq 0x2150
jmp 0x282d
leaq -0xe8(%rbp), %rdi
callq 0x3020
leaq -0xb8(%rbp), %rdi
callq 0x2e70
movq %rax, -0x278(%rbp)
jmp 0x284e
movq -0x278(%rbp), %rsi
movq 0x876c(%rip), %rdi      # 0xafc8
callq 0x2030
movq %rax, -0x280(%rbp)
jmp 0x286a
movq -0x280(%rbp), %rdi
movq 0x8740(%rip), %rsi      # 0xafb8
callq 0x2150
jmp 0x287f
movq $0x0, -0x198(%rbp)
movq -0x198(%rbp), %rax
movq %rax, -0x290(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x2e70
movq %rax, -0x288(%rbp)
jmp 0x28ad
movq -0x290(%rbp), %rax
movq -0x288(%rbp), %rcx
cmpq %rcx, %rax
je 0x2a8f
movq -0x198(%rbp), %rsi
leaq -0xb8(%rbp), %rdi
callq 0x3040
movq %rax, -0x298(%rbp)
jmp 0x28e0
movq -0x298(%rbp), %rsi
movq 0x86da(%rip), %rdi      # 0xafc8
callq 0x2110
movq %rax, -0x2a0(%rbp)
jmp 0x28fc
movq -0x2a0(%rbp), %rdi
leaq 0x470a(%rip), %rsi      # 0x7014
callq 0x2120
jmp 0x2911
jmp 0x2913
movq -0x198(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x198(%rbp)
jmp 0x288a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x2acc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x29d8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x29cc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x29c0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x158(%rbp), %rax
movq %rax, -0x2b0(%rbp)
addq $0x60, %rax
movq %rax, -0x2a8(%rbp)
movq -0x2a8(%rbp), %rdi
addq $-0x20, %rdi
movq %rdi, -0x2b8(%rbp)
callq 0x20d0
movq -0x2b0(%rbp), %rcx
movq -0x2b8(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x2a8(%rbp)
jne 0x298d
jmp 0x29c0
leaq -0x163(%rbp), %rdi
callq 0x2160
leaq -0x162(%rbp), %rdi
callq 0x2160
leaq -0x161(%rbp), %rdi
callq 0x2160
testb $0x1, -0x164(%rbp)
jne 0x29ef
jmp 0x2a3c
movq -0x160(%rbp), %rax
leaq -0x158(%rbp), %rcx
cmpq %rax, %rcx
movq %rax, -0x2c0(%rbp)
je 0x2a3a
movq -0x2c0(%rbp), %rdi
addq $-0x20, %rdi
movq %rdi, -0x2c8(%rbp)
callq 0x20d0
movq -0x2c8(%rbp), %rax
leaq -0x158(%rbp), %rcx
cmpq %rcx, %rax
movq %rax, -0x2c0(%rbp)
jne 0x2a09
jmp 0x2a3c
jmp 0x2acc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x2a81
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x2a75
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x188(%rbp), %rdi
callq 0x20d0
leaq -0x189(%rbp), %rdi
callq 0x2160
leaq -0xe8(%rbp), %rdi
callq 0x3020
jmp 0x2acc
movq 0x8532(%rip), %rdi      # 0xafc8
movq 0x851b(%rip), %rsi      # 0xafb8
callq 0x2150
jmp 0x2aa4
movl $0x0, -0x4(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x3020
leaq -0x40(%rbp), %rdi
callq 0x3100
movl -0x4(%rbp), %eax
addq $0x2d0, %rsp            # imm = 0x2D0
popq %rbp
retq
leaq -0xb8(%rbp), %rdi
callq 0x3020
leaq -0x40(%rbp), %rdi
callq 0x3100
movq -0x68(%rbp), %rdi
callq 0x21f0
nopw (%rax,%rax)