// File: 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
subq $0x130, %rsp            # imm = 0x130
movl $0x0, -0x4(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x26c0
leaq -0x58(%rbp), %rdi
callq 0x2190
movq 0x5c85(%rip), %rdi      # 0x7fe0
leaq -0x58(%rbp), %rsi
callq 0x2160
movq %rax, -0xc0(%rbp)
jmp 0x236d
movq -0xc0(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x2150
movb %al, -0xc1(%rbp)
jmp 0x238b
movb -0xc1(%rbp), %al
testb $0x1, %al
jne 0x2397
jmp 0x23d1
leaq -0x38(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x26e0
movq %rax, -0xd0(%rbp)
jmp 0x23ad
movq -0xd0(%rbp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
jmp 0x2354
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x2697
leaq -0x89(%rbp), %rdi
movq %rdi, -0xd8(%rbp)
callq 0x21e0
movq -0xd8(%rbp), %rdx
leaq 0x2c12(%rip), %rsi      # 0x5004
leaq -0x88(%rbp), %rdi
callq 0x2180
jmp 0x2400
leaq -0x89(%rbp), %rdi
callq 0x2130
leaq -0x38(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x27c0
movq %rax, -0xe0(%rbp)
jmp 0x2425
movq -0xe0(%rbp), %rax
cmpq $0x0, %rax
je 0x24c2
movq 0x5b93(%rip), %rdi      # 0x7fd0
leaq 0x2bc4(%rip), %rsi      # 0x5008
callq 0x20f0
movq %rax, -0xe8(%rbp)
jmp 0x2452
movq -0xe8(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x20e0
movq %rax, -0xf0(%rbp)
jmp 0x246e
movq -0xf0(%rbp), %rdi
leaq 0x2b91(%rip), %rsi      # 0x500d
callq 0x20f0
jmp 0x2483
jmp 0x2511
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x89(%rbp), %rdi
callq 0x2130
jmp 0x2697
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x20a0
jmp 0x2697
movq 0x5b07(%rip), %rdi      # 0x7fd0
leaq 0x2b47(%rip), %rsi      # 0x5017
callq 0x20f0
movq %rax, -0xf8(%rbp)
jmp 0x24de
movq -0xf8(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x20e0
movq %rax, -0x100(%rbp)
jmp 0x24fa
movq -0x100(%rbp), %rdi
leaq 0x2b16(%rip), %rsi      # 0x501e
callq 0x20f0
jmp 0x250f
jmp 0x2511
leaq 0x2b13(%rip), %rsi      # 0x502b
leaq -0x88(%rbp), %rdi
callq 0x2170
jmp 0x2526
leaq -0x98(%rbp), %rdi
callq 0x27f0
leaq -0x38(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x2810
movq %rax, -0x108(%rbp)
jmp 0x254b
movq -0x108(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rax
movq %rax, -0x98(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x2870
movq %rax, -0xa8(%rbp)
leaq -0x98(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x2840
testb $0x1, %al
jne 0x2590
jmp 0x25e2
movq 0x5a39(%rip), %rdi      # 0x7fd0
leaq 0x2a79(%rip), %rsi      # 0x5017
callq 0x20f0
movq %rax, -0x110(%rbp)
jmp 0x25ac
movq -0x110(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x20e0
movq %rax, -0x118(%rbp)
jmp 0x25c8
movq -0x118(%rbp), %rdi
leaq 0x2a48(%rip), %rsi      # 0x501e
callq 0x20f0
jmp 0x25dd
jmp 0x2666
movq -0x98(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0xb0(%rbp), %rsi
leaq -0x38(%rbp), %rdi
callq 0x28a0
movq %rax, -0x120(%rbp)
jmp 0x2609
movq -0x120(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq 0x59b2(%rip), %rdi      # 0x7fd0
leaq 0x29e3(%rip), %rsi      # 0x5008
callq 0x20f0
movq %rax, -0x128(%rbp)
jmp 0x2633
movq -0x128(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x20e0
movq %rax, -0x130(%rbp)
jmp 0x264f
movq -0x130(%rbp), %rdi
leaq 0x29d2(%rip), %rsi      # 0x502f
callq 0x20f0
jmp 0x2664
jmp 0x2666
movl $0x0, -0x4(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x20a0
leaq -0x58(%rbp), %rdi
callq 0x20a0
leaq -0x38(%rbp), %rdi
callq 0x28e0
movl -0x4(%rbp), %eax
addq $0x130, %rsp            # imm = 0x130
popq %rbp
retq
leaq -0x58(%rbp), %rdi
callq 0x20a0
leaq -0x38(%rbp), %rdi
callq 0x28e0
movq -0x60(%rbp), %rdi
callq 0x21d0
nopw %cs:(%rax,%rax)
nopl (%rax)