// File: /workspace/github_cpp_makefile_star2_O3/iZhangHui[P]CppPrimer/CH11_AssociativeContainers/examples/erasemap.cc
// Function: main
int main()
{
	map<string, size_t> word_count;  // empty map from string to size_t
	string word;
	while (cin >> word)
		++word_count[word];

	string removal_word = "the";

	// two ways to remove an entry from a map
	// 1. by key
	// erase on a key returns the number of elements removed
	if (word_count.erase(removal_word))
		 cout << "ok: " << removal_word << " removed\n";
	else
		cout << "oops: " << removal_word << " not found!\n";

	// 2. by removing an iterator to the element we want removed
	removal_word = "The";  // strings are case sensitive
	map<string,size_t>::iterator where;
	where = word_count.find(removal_word);  // should be gone

	if (where == word_count.end())
		 cout << "oops: " << removal_word << " not found!\n";
	else {
		 word_count.erase(where);   // erase iterator returns void
		 cout << "ok: " << removal_word << " removed!\n";
	}
		return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
leaq -0x90(%rbp), %r13
movl $0x0, (%r13)
xorl %eax, %eax
movq %rax, 0x8(%r13)
movq %r13, 0x10(%r13)
movq %r13, 0x18(%r13)
movq %rax, 0x20(%r13)
leaq -0x58(%rbp), %r12
movq %r12, -0x10(%r12)
movq %rax, -0x8(%r12)
movb $0x0, (%r12)
movq 0x2cd8(%rip), %rbx      # 0x4fe0
leaq -0x68(%rbp), %r14
leaq -0x98(%rbp), %r15
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2110
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x233c
movq %r15, %rdi
movq %r14, %rsi
callq 0x254c
incq (%rax)
jmp 0x2313
leaq -0x38(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0xcb9(%rip), %rsi       # 0x3004
leaq 0xcb5(%rip), %rdx       # 0x3007
leaq -0x48(%rbp), %rdi
callq 0x2a76
leaq -0x98(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x2b14
leaq -0x98(%rbp), %rdi
movq 0x28(%rdi), %rbx
movq %rax, %rsi
callq 0x2bd0
cmpq -0x70(%rbp), %rbx
jne 0x23be
movq 0x2c45(%rip), %rdi      # 0x4fd0
leaq 0xc85(%rip), %rsi       # 0x3017
movl $0x6, %edx
callq 0x20f0
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq 0x2c25(%rip), %rdi      # 0x4fd0
callq 0x20f0
movl $0xc, %edx
leaq 0xc62(%rip), %rsi       # 0x301e
jmp 0x23f6
movq 0x2c0b(%rip), %rdi      # 0x4fd0
leaq 0xc3c(%rip), %rsi       # 0x3008
movl $0x4, %edx
callq 0x20f0
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq 0x2beb(%rip), %rdi      # 0x4fd0
callq 0x20f0
movl $0x9, %edx
leaq 0xc17(%rip), %rsi       # 0x300d
movq %rax, %rdi
callq 0x20f0
leaq -0x48(%rbp), %rdi
movq 0x8(%rdi), %rdx
leaq 0xc1e(%rip), %rcx       # 0x302b
movl $0x3, %r8d
xorl %esi, %esi
callq 0x2140
leaq -0x98(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x2cdc
cmpq %r13, %rax
je 0x2478
leaq -0x98(%rbp), %rdi
movq %rax, %rsi
callq 0x2d2c
movq 0x2b8b(%rip), %rdi      # 0x4fd0
leaq 0xbbc(%rip), %rsi       # 0x3008
movl $0x4, %edx
callq 0x20f0
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq 0x2b6b(%rip), %rdi      # 0x4fd0
callq 0x20f0
movl $0xa, %edx
leaq 0xbb9(%rip), %rsi       # 0x302f
jmp 0x24b0
movq 0x2b51(%rip), %rdi      # 0x4fd0
leaq 0xb91(%rip), %rsi       # 0x3017
movl $0x6, %edx
callq 0x20f0
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq 0x2b31(%rip), %rdi      # 0x4fd0
callq 0x20f0
movl $0xc, %edx
leaq 0xb6e(%rip), %rsi       # 0x301e
movq %rax, %rdi
callq 0x20f0
movq -0x48(%rbp), %rdi
cmpq %r14, %rdi
je 0x24cd
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x20d0
movq -0x68(%rbp), %rdi
cmpq %r12, %rdi
je 0x24e2
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x20d0
leaq -0x98(%rbp), %rdi
callq 0x25da
xorl %eax, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2505
jmp 0x251f
jmp 0x2505
movq %rax, %rbx
movq -0x48(%rbp), %rdi
cmpq %r14, %rdi
je 0x2522
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x20d0
jmp 0x2522
movq %rax, %rbx
movq -0x68(%rbp), %rdi
cmpq %r12, %rdi
je 0x2537
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x20d0
leaq -0x98(%rbp), %rdi
callq 0x25da
movq %rbx, %rdi
callq 0x2160
nop