// File: /workspace/github_cpp_makefile_star2_O2/iZhangHui[P]CppPrimer/CH16_TemplatesAndGenericProgramming/examples/trail-ret.cc
// Function: main
int main()
{
	vector<int> vi = {1,2,3,4,5};
	Blob<string> ca = { "hi", "bye" };

	auto& i = reffcn(vi.begin(), vi.end()); // reffcn should return int&
	auto& s = reffcn(ca.begin(), ca.end()); // reffcn should return string&

	vi = {1,2,3,4};
	for (auto i : vi)
		cout << i << " ";
	cout << endl;

	auto& ref = reffcn(vi.begin(), vi.end());  // ref is int&
	// auto ref = reffcn(vi.begin(), vi.end());
	ref = 5; // changes the value of *beg to which ref refers
	for (auto i : vi)
		cout << i << " ";
	cout << endl;

	auto val = valfcn(vi.begin(), vi.end()); // val is int
	cout << val << endl;  // will print 5

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0xb0, %rsp
movups 0xd0b(%rip), %xmm0      # 0x3020
leaq -0xb0(%rbp), %rsi
movaps %xmm0, (%rsi)
movl $0x5, 0x10(%rsi)
leaq -0x50(%rbp), %rdi
pushq $0x5
popq %rdx
leaq -0x38(%rbp), %rcx
callq 0x253c
leaq 0xcf7(%rip), %rsi       # 0x3034
leaq -0xb0(%rbp), %rdi
leaq -0x22(%rbp), %rdx
callq 0x2060
leaq -0x90(%rbp), %rdi
leaq 0xcdc(%rip), %rsi       # 0x3037
leaq -0x21(%rbp), %rdx
callq 0x2060
leaq -0x38(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
pushq $0x2
popq %rdx
callq 0x2572
pushq $0x20
popq %rbx
leaq (%rbx,%rbp), %rdi
addq $-0xb0, %rdi
callq 0x2080
addq $-0x20, %rbx
cmpq $-0x20, %rbx
jne 0x237a
leaq -0x68(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x2594
leaq -0xc8(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x25b2
leaq -0x68(%rbp), %rdi
callq 0x25dc
leaq -0xc0(%rbp), %rdi
callq 0x2836
leaq -0x60(%rbp), %rdi
callq 0x2836
movaps 0xc3a(%rip), %xmm0      # 0x3010
leaq -0xa0(%rbp), %rdx
movups %xmm0, -0x10(%rdx)
leaq -0x50(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x2dd4
movq -0x50(%rbp), %r15
movq -0x48(%rbp), %r12
movq 0x2bc0(%rip), %rbx      # 0x4fc0
leaq 0xc34(%rip), %r14       # 0x303b
cmpq %r12, %r15
je 0x2428
movl (%r15), %esi
movq %rbx, %rdi
callq 0x21a0
movq %rax, %rdi
movq %r14, %rsi
callq 0x20f0
addq $0x4, %r15
jmp 0x2407
movq 0x2b91(%rip), %rdi      # 0x4fc0
callq 0x2090
movq -0x50(%rbp), %r15
movl $0x5, (%r15)
movq -0x48(%rbp), %r12
movq 0x2b76(%rip), %rbx      # 0x4fc0
leaq 0xbea(%rip), %r14       # 0x303b
cmpq %r12, %r15
je 0x2472
movl (%r15), %esi
movq %rbx, %rdi
callq 0x21a0
movq %rax, %rdi
movq %r14, %rsi
callq 0x20f0
addq $0x4, %r15
jmp 0x2451
movq 0x2b47(%rip), %rdi      # 0x4fc0
callq 0x2090
movq -0x50(%rbp), %rax
movl (%rax), %esi
movq 0x2b35(%rip), %rdi      # 0x4fc0
callq 0x21a0
movq %rax, %rdi
callq 0x2090
leaq -0x30(%rbp), %rdi
callq 0x2798
leaq -0x50(%rbp), %rdi
callq 0x28da
xorl %eax, %eax
addq $0xb0, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
jmp 0x251e
jmp 0x251e
movq %rax, %rbx
leaq -0xc0(%rbp), %rdi
callq 0x2836
jmp 0x24d4
movq %rax, %rbx
leaq -0x60(%rbp), %rdi
callq 0x2836
jmp 0x2521
movq %rax, %rbx
pushq $0x20
popq %r14
leaq (%r14,%rbp), %rdi
addq $-0xb0, %rdi
callq 0x2080
addq $-0x20, %r14
cmpq $-0x20, %r14
jne 0x24e6
jmp 0x252a
movq %rax, %rbx
leaq -0xb0(%rbp), %rdi
callq 0x2080
jmp 0x252a
movq %rax, %rbx
jmp 0x252a
jmp 0x251e
jmp 0x251e
jmp 0x251e
movq %rax, %rbx
leaq -0x30(%rbp), %rdi
callq 0x2798
leaq -0x50(%rbp), %rdi
callq 0x28da
movq %rbx, %rdi
callq 0x21b0
nop