// File: /workspace/github_cpp_makefile_star2_O1/iZhangHui[P]CppPrimer/CH17_SpecializedLibraryFacilities/examples/tuple.cc
// Function: main
int main()
{
	// tuple that represents a bookstore transaction: 
	// ISBN, count, price per book
	auto item = make_tuple("0-999-78345-X", 3, 20.00);
	auto book = get<0>(item);      // returns the first member of item
	auto cnt = get<1>(item);       // returns the second member of item
	auto price = get<2>(item)/cnt; // returns the last member of item
	get<2>(item) *= 0.8;           // apply 20% discount
	
	cout << book << " " << cnt << " " << price << endl;

	typedef decltype(item) trans; // trans is the type of item 
	
	// returns the number of members in object's of type trans
	size_t sz = tuple_size<trans>::value;  // returns 3

	// cnt has the same type as the second member in item
	tuple_element<1, trans>::type cnt2 = get<1>(item); // cnt is an int
	tuple_element<0, trans>::type book2 = get<0>(item);
	tuple_element<2, trans>::type price2 = get<2>(item);
	cout << tuple_size<trans>::value << endl;
	
	cout << book2 << " " << cnt2 << " " << price2 << endl;
	
	tuple<size_t, size_t, size_t> threeD;  // all three members set to 0
	tuple<string, vector<double>, int, list<int>>
	    someVal("constants", {3.14, 2.718}, 42, {0,1,2,3,4,5});
	
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0xe0, %rsp
movq 0x2d03(%rip), %rbx      # 0x3fd8
leaq 0xd3c(%rip), %r15       # 0x2018
movl $0xd, %edx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x1100
leaq 0xd33(%rip), %r14       # 0x2026
movl $0x1, %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1100
movq %rbx, %rdi
movl $0x3, %esi
callq 0x1140
movq %rax, %r12
movl $0x1, %edx
movq %rax, %rdi
movq %r14, %rsi
callq 0x1100
movsd 0xcdd(%rip), %xmm0      # 0x2008
movq %r12, %rdi
callq 0x1120
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x10d0
movsbl %al, %esi
movq %r12, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1080
movl $0x3, %esi
movq %rbx, %rdi
callq 0x1070
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x10d0
movsbl %al, %esi
movq %r12, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1080
movl $0xd, %edx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x1100
movl $0x1, %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1100
movq %rbx, %rdi
movl $0x3, %esi
callq 0x1140
movq %rax, %rbx
movl $0x1, %edx
movq %rax, %rdi
movq %r14, %rsi
callq 0x1100
movsd 0xc34(%rip), %xmm0      # 0x2010
movq %rbx, %rdi
callq 0x1120
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x10d0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1080
leaq -0x50(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0xc0b(%rip), %rsi       # 0x2028
leaq 0xc0d(%rip), %rdx       # 0x2031
leaq -0x60(%rbp), %rdi
callq 0x193a
movabsq $0x40091eb851eb851f, %rax # imm = 0x40091EB851EB851F
leaq -0xe0(%rbp), %rsi
movq %rax, (%rsi)
movabsq $0x4005be76c8b43958, %rax # imm = 0x4005BE76C8B43958
movq %rax, 0x8(%rsi)
leaq -0x40(%rbp), %rdi
leaq -0x22(%rbp), %rcx
movl $0x2, %edx
callq 0x15ce
movl $0x2a, -0x28(%rbp)
movups 0xc21(%rip), %xmm0      # 0x2090
leaq -0x100(%rbp), %rsi
movaps %xmm0, (%rsi)
movabsq $0x500000004, %rax      # imm = 0x500000004
movq %rax, 0x10(%rsi)
leaq -0x78(%rbp), %rdi
leaq -0x21(%rbp), %rcx
movl $0x6, %edx
callq 0x1614
leaq -0xd0(%rbp), %rbx
leaq -0x60(%rbp), %rsi
leaq -0x40(%rbp), %rdx
leaq -0x28(%rbp), %rcx
leaq -0x78(%rbp), %r14
movq %rbx, %rdi
movq %r14, %r8
callq 0x166c
movq -0x78(%rbp), %rdi
cmpq %r14, %rdi
je 0x14d9
movq (%rdi), %r12
movl $0x18, %esi
callq 0x10f0
movq %r12, %rdi
cmpq %r14, %r12
jne 0x14c4
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x14ee
movq -0x30(%rbp), %rsi
subq %rdi, %rsi
callq 0x10f0
movq -0x60(%rbp), %rdi
cmpq %r15, %rdi
je 0x1503
movq -0x50(%rbp), %rsi
incq %rsi
callq 0x10f0
leaq -0x88(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1522
movq -0x88(%rbp), %rsi
incq %rsi
callq 0x10f0
movq -0xb0(%rbp), %rdi
testq %rdi, %rdi
je 0x153d
movq -0xa0(%rbp), %rsi
subq %rdi, %rsi
callq 0x10f0
movq -0xd0(%rbp), %rdi
cmpq %rbx, %rdi
je 0x155e
movq (%rdi), %r14
movl $0x18, %esi
callq 0x10f0
movq %r14, %rdi
cmpq %rbx, %r14
jne 0x1549
xorl %eax, %eax
addq $0xe0, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq -0x78(%rbp), %rdi
cmpq %r14, %rdi
je 0x1596
movq (%rdi), %r12
movl $0x18, %esi
callq 0x10f0
movq %r12, %rdi
cmpq %r14, %r12
jne 0x157c
jmp 0x1596
movq %rax, %rbx
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x15b0
movq -0x30(%rbp), %rsi
subq %rdi, %rsi
callq 0x10f0
jmp 0x15b0
movq %rax, %rbx
movq -0x60(%rbp), %rdi
cmpq %r15, %rdi
je 0x15c5
movq -0x50(%rbp), %rsi
incq %rsi
callq 0x10f0
movq %rbx, %rdi
callq 0x1150
nop