// File: /workspace/github_cpp_makefile_star2_O2/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 %r12
pushq %rbx
subq $0x80, %rsp
leaq -0x70(%rbp), %r12
andl $0x0, (%r12)
andq $0x0, 0x8(%r12)
movq %r12, 0x10(%r12)
movq %r12, 0x18(%r12)
andq $0x0, 0x20(%r12)
leaq -0x88(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq 0x2ca9(%rip), %rbx      # 0x4fe0
leaq -0x98(%rbp), %r14
leaq -0x78(%rbp), %r15
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2140
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x236b
movq %r15, %rdi
movq %r14, %rsi
callq 0x24d0
incq (%rax)
jmp 0x2342
leaq 0xc92(%rip), %rsi       # 0x3004
leaq -0x48(%rbp), %rdi
leaq -0x21(%rbp), %rdx
callq 0x2070
leaq -0x78(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x29cc
testq %rax, %rax
je 0x23b9
movq 0x2c38(%rip), %rdi      # 0x4fd0
leaq 0xc69(%rip), %rsi       # 0x3008
callq 0x20f0
leaq -0x48(%rbp), %rsi
movq %rax, %rdi
callq 0x20e0
leaq 0xc56(%rip), %rsi       # 0x300d
jmp 0x23df
movq 0x2c10(%rip), %rdi      # 0x4fd0
leaq 0xc50(%rip), %rsi       # 0x3017
callq 0x20f0
leaq -0x48(%rbp), %rsi
movq %rax, %rdi
callq 0x20e0
leaq 0xc3f(%rip), %rsi       # 0x301e
movq %rax, %rdi
callq 0x20f0
leaq 0xc3d(%rip), %rsi       # 0x302b
leaq -0x48(%rbp), %rdi
callq 0x21a0
leaq -0x78(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x2bb0
cmpq %r12, %rax
je 0x243d
leaq -0x78(%rbp), %rdi
movq %rax, %rsi
callq 0x2bf8
movq 0x2bb4(%rip), %rdi      # 0x4fd0
leaq 0xbe5(%rip), %rsi       # 0x3008
callq 0x20f0
leaq -0x48(%rbp), %rsi
movq %rax, %rdi
callq 0x20e0
leaq 0xbf4(%rip), %rsi       # 0x302f
jmp 0x2463
movq 0x2b8c(%rip), %rdi      # 0x4fd0
leaq 0xbcc(%rip), %rsi       # 0x3017
callq 0x20f0
leaq -0x48(%rbp), %rsi
movq %rax, %rdi
callq 0x20e0
leaq 0xbbb(%rip), %rsi       # 0x301e
movq %rax, %rdi
callq 0x20f0
leaq -0x48(%rbp), %rdi
callq 0x2090
leaq -0x98(%rbp), %rdi
callq 0x2090
leaq -0x78(%rbp), %rdi
callq 0x2548
xorl %eax, %eax
addq $0x80, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
jmp 0x24a1
jmp 0x24af
jmp 0x24a1
movq %rax, %rbx
leaq -0x48(%rbp), %rdi
callq 0x2090
jmp 0x24b2
movq %rax, %rbx
leaq -0x98(%rbp), %rdi
callq 0x2090
leaq -0x78(%rbp), %rdi
callq 0x2548
movq %rbx, %rdi
callq 0x2190
nop