// File: iZhangHui[P]CppPrimer/CH11_AssociativeContainers/examples/setOps.cc
// Function: main
int main()
{
	// define a vector with 20 elements,
	// holding two copies of each number from 0 to 9
	vector<int> ivec;
	for (vector<int>::size_type i = 10; i != 0; --i) {
		ivec.push_back(i);
		ivec.push_back(i);  // duplicate copies of each number
	}

	// iset holds unique elements from ivec; miset holds all 20 elements
	set<int> iset(ivec.cbegin(), ivec.cend());
	multiset<int> miset(ivec.cbegin(), ivec.cend());

	cout << ivec.size() << endl;    // prints 20
	cout << iset.size() << endl;    // prints 10
	for (const auto item : iset)
		cout << item << endl;

	cout << miset.size() << endl;   // prints 20

	// returns an iterator that refers to the element with key == 1
	iset.find(1);
	iset.find(11);  // returns the iterator == iset.end()
	iset.count(1);  // returns 1
	iset.count(11); // returns 0

	// returns an iterator to the first element with key == 1
	iset.find(1);
	iset.find(11);   // returns the iterator == iset.end()
	miset.count(1);  // returns 2
	miset.count(11); // returns 0

	set<string> set1;    // empty set
	set1.insert("the");  // set1 now has one element
	set1.insert("and");  // set1 now has two elements

	ivec = {2,4,6,8,2,4,6,8}; // ivec now has eight elements
	set<int> set2;            // empty set
	set2.insert(ivec.cbegin(), ivec.cend()); // set2 has four elements
	set2.insert({1,3,5,7,1,3,5,7});      // set2 now has eight elements
	for (const auto item : set2)
		cout << item << endl;

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x330, %rsp            # imm = 0x330
movl $0x0, -0x4(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x1a60
movq $0xa, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x1385
movl -0x28(%rbp), %eax
movl %eax, -0x2c(%rbp)
leaq -0x20(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x1a80
jmp 0x134f
movl -0x28(%rbp), %eax
movl %eax, -0x40(%rbp)
leaq -0x20(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x1a80
jmp 0x1364
jmp 0x1366
movq -0x28(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x1333
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x1a4c
leaq -0x20(%rbp), %rdi
movq %rdi, -0x298(%rbp)
callq 0x1ab0
movq -0x298(%rbp), %rdi
movq %rax, -0x78(%rbp)
callq 0x1ae0
movq %rax, -0x80(%rbp)
movq -0x78(%rbp), %rsi
movq -0x80(%rbp), %rdx
leaq -0x70(%rbp), %rdi
callq 0x1b10
jmp 0x13bc
leaq -0x20(%rbp), %rdi
movq %rdi, -0x2a0(%rbp)
callq 0x1ab0
movq -0x2a0(%rbp), %rdi
movq %rax, -0xb8(%rbp)
callq 0x1ae0
movq %rax, -0xc0(%rbp)
movq -0xb8(%rbp), %rsi
movq -0xc0(%rbp), %rdx
leaq -0xb0(%rbp), %rdi
callq 0x1b90
jmp 0x1402
leaq -0x20(%rbp), %rdi
callq 0x1c10
movq %rax, %rsi
movq 0x8bc3(%rip), %rdi      # 0x9fd8
callq 0x1050
movq %rax, -0x2a8(%rbp)
jmp 0x1423
movq -0x2a8(%rbp), %rdi
movq 0x8b97(%rip), %rsi      # 0x9fc8
callq 0x1120
jmp 0x1438
leaq -0x70(%rbp), %rdi
callq 0x1c30
movq %rax, %rsi
movq 0x8b8d(%rip), %rdi      # 0x9fd8
callq 0x1050
movq %rax, -0x2b0(%rbp)
jmp 0x1459
movq -0x2b0(%rbp), %rdi
movq 0x8b61(%rip), %rsi      # 0x9fc8
callq 0x1120
jmp 0x146e
leaq -0x70(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0xc8(%rbp), %rdi
callq 0x1c50
movq %rax, -0xd0(%rbp)
movq -0xc8(%rbp), %rdi
callq 0x1c80
movq %rax, -0xd8(%rbp)
leaq -0xd0(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x1cb0
testb $0x1, %al
jne 0x14b8
jmp 0x152e
leaq -0xd0(%rbp), %rdi
callq 0x1ce0
movl (%rax), %eax
movl %eax, -0xdc(%rbp)
movl -0xdc(%rbp), %esi
movq 0x8aff(%rip), %rdi      # 0x9fd8
callq 0x11a0
movq %rax, -0x2b8(%rbp)
jmp 0x14e7
movq -0x2b8(%rbp), %rdi
movq 0x8ad3(%rip), %rsi      # 0x9fc8
callq 0x1120
jmp 0x14fc
jmp 0x14fe
leaq -0xd0(%rbp), %rdi
callq 0x1d00
jmp 0x149f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x1a43
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x1a37
leaq -0xb0(%rbp), %rdi
callq 0x1d30
movq %rax, %rsi
movq 0x8a94(%rip), %rdi      # 0x9fd8
callq 0x1050
movq %rax, -0x2c0(%rbp)
jmp 0x1552
movq -0x2c0(%rbp), %rdi
movq 0x8a68(%rip), %rsi      # 0x9fc8
callq 0x1120
jmp 0x1567
movl $0x1, -0xe0(%rbp)
leaq -0x70(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x1d50
movq %rax, -0x2c8(%rbp)
jmp 0x158a
movq -0x2c8(%rbp), %rax
movq %rax, -0xe8(%rbp)
movl $0xb, -0xec(%rbp)
leaq -0x70(%rbp), %rdi
leaq -0xec(%rbp), %rsi
callq 0x1d50
movq %rax, -0x2d0(%rbp)
jmp 0x15bb
movq -0x2d0(%rbp), %rax
movq %rax, -0xf8(%rbp)
movl $0x1, -0xfc(%rbp)
leaq -0x70(%rbp), %rdi
leaq -0xfc(%rbp), %rsi
callq 0x1d90
jmp 0x15e5
movl $0xb, -0x100(%rbp)
leaq -0x70(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0x1d90
jmp 0x1601
movl $0x1, -0x104(%rbp)
leaq -0x70(%rbp), %rdi
leaq -0x104(%rbp), %rsi
callq 0x1d50
movq %rax, -0x2d8(%rbp)
jmp 0x1624
movq -0x2d8(%rbp), %rax
movq %rax, -0x110(%rbp)
movl $0xb, -0x114(%rbp)
leaq -0x70(%rbp), %rdi
leaq -0x114(%rbp), %rsi
callq 0x1d50
movq %rax, -0x2e0(%rbp)
jmp 0x1655
movq -0x2e0(%rbp), %rax
movq %rax, -0x120(%rbp)
movl $0x1, -0x124(%rbp)
leaq -0xb0(%rbp), %rdi
leaq -0x124(%rbp), %rsi
callq 0x1df0
jmp 0x1682
movl $0xb, -0x128(%rbp)
leaq -0xb0(%rbp), %rdi
leaq -0x128(%rbp), %rsi
callq 0x1df0
jmp 0x16a1
leaq -0x158(%rbp), %rdi
callq 0x1e20
leaq -0x179(%rbp), %rdi
movq %rdi, -0x2e8(%rbp)
callq 0x11c0
movq -0x2e8(%rbp), %rdx
leaq 0x4936(%rip), %rsi      # 0x6004
leaq -0x178(%rbp), %rdi
callq 0x1150
jmp 0x16dc
leaq -0x158(%rbp), %rdi
leaq -0x178(%rbp), %rsi
callq 0x1e40
movb %dl, -0x2f1(%rbp)
movq %rax, -0x2f0(%rbp)
jmp 0x16fe
movb -0x2f1(%rbp), %al
movq -0x2f0(%rbp), %rcx
movq %rcx, -0x190(%rbp)
movb %al, -0x188(%rbp)
leaq -0x178(%rbp), %rdi
callq 0x10b0
leaq -0x179(%rbp), %rdi
callq 0x1130
leaq -0x1b1(%rbp), %rdi
movq %rdi, -0x300(%rbp)
callq 0x11c0
movq -0x300(%rbp), %rdx
leaq 0x48b7(%rip), %rsi      # 0x6008
leaq -0x1b0(%rbp), %rdi
callq 0x1150
jmp 0x175f
leaq -0x158(%rbp), %rdi
leaq -0x1b0(%rbp), %rsi
callq 0x1e40
movb %dl, -0x309(%rbp)
movq %rax, -0x308(%rbp)
jmp 0x1781
movb -0x309(%rbp), %al
movq -0x308(%rbp), %rcx
movq %rcx, -0x1c8(%rbp)
movb %al, -0x1c0(%rbp)
leaq -0x1b0(%rbp), %rdi
callq 0x10b0
leaq -0x1b1(%rbp), %rdi
callq 0x1130
movups 0x48ae(%rip), %xmm0     # 0x6068
movaps %xmm0, -0x1f0(%rbp)
movups 0x4890(%rip), %xmm0     # 0x6058
movaps %xmm0, -0x200(%rbp)
leaq -0x200(%rbp), %rax
movq %rax, -0x1d8(%rbp)
movq $0x8, -0x1d0(%rbp)
movq -0x1d8(%rbp), %rsi
movq -0x1d0(%rbp), %rdx
leaq -0x20(%rbp), %rdi
callq 0x1e90
jmp 0x1801
leaq -0x230(%rbp), %rdi
movq %rdi, -0x318(%rbp)
callq 0x1ee0
leaq -0x20(%rbp), %rdi
movq %rdi, -0x320(%rbp)
callq 0x1ab0
movq -0x320(%rbp), %rdi
movq %rax, -0x238(%rbp)
callq 0x1ae0
movq -0x318(%rbp), %rdi
movq %rax, -0x240(%rbp)
movq -0x238(%rbp), %rsi
movq -0x240(%rbp), %rdx
callq 0x1f00
jmp 0x185a
movups 0x4827(%rip), %xmm0     # 0x6088
movaps %xmm0, -0x260(%rbp)
movups 0x4809(%rip), %xmm0     # 0x6078
movaps %xmm0, -0x270(%rbp)
leaq -0x270(%rbp), %rax
movq %rax, -0x250(%rbp)
movq $0x8, -0x248(%rbp)
movq -0x250(%rbp), %rsi
movq -0x248(%rbp), %rdx
leaq -0x230(%rbp), %rdi
callq 0x1f40
jmp 0x18ab
leaq -0x230(%rbp), %rax
movq %rax, -0x278(%rbp)
movq -0x278(%rbp), %rdi
callq 0x1c50
movq %rax, -0x280(%rbp)
movq -0x278(%rbp), %rdi
callq 0x1c80
movq %rax, -0x288(%rbp)
leaq -0x280(%rbp), %rdi
leaq -0x288(%rbp), %rsi
callq 0x1cb0
testb $0x1, %al
jne 0x18fb
jmp 0x19e2
leaq -0x280(%rbp), %rdi
callq 0x1ce0
movl (%rax), %eax
movl %eax, -0x28c(%rbp)
movl -0x28c(%rbp), %esi
movq 0x86bc(%rip), %rdi      # 0x9fd8
callq 0x11a0
movq %rax, -0x328(%rbp)
jmp 0x192a
movq -0x328(%rbp), %rdi
movq 0x8690(%rip), %rsi      # 0x9fc8
callq 0x1120
jmp 0x193f
jmp 0x1941
leaq -0x280(%rbp), %rdi
callq 0x1d00
jmp 0x18df
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x1975
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x178(%rbp), %rdi
callq 0x10b0
leaq -0x179(%rbp), %rdi
callq 0x1130
jmp 0x1a2b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x19ac
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x1b0(%rbp), %rdi
callq 0x10b0
leaq -0x1b1(%rbp), %rdi
callq 0x1130
jmp 0x1a2b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x1a2b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x230(%rbp), %rdi
callq 0x1f90
jmp 0x1a2b
movl $0x0, -0x4(%rbp)
leaq -0x230(%rbp), %rdi
callq 0x1f90
leaq -0x158(%rbp), %rdi
callq 0x1fb0
leaq -0xb0(%rbp), %rdi
callq 0x1fd0
leaq -0x70(%rbp), %rdi
callq 0x1f90
leaq -0x20(%rbp), %rdi
callq 0x1ff0
movl -0x4(%rbp), %eax
addq $0x330, %rsp            # imm = 0x330
popq %rbp
retq
leaq -0x158(%rbp), %rdi
callq 0x1fb0
leaq -0xb0(%rbp), %rdi
callq 0x1fd0
leaq -0x70(%rbp), %rdi
callq 0x1f90
leaq -0x20(%rbp), %rdi
callq 0x1ff0
movq -0x38(%rbp), %rdi
callq 0x11b0
nop