// File: /workspace/github_cpp_makefile_star2_O2/iZhangHui[P]CppPrimer/CH14_OverloadedOperationsAndConversions/examples/absInt.cc
// Function: main
int main()
{
    int i = -42;
    absInt absObj;           // object that has a function-call operator
    unsigned ui = absObj(i); // passes i to absObj.operator()
    cout << i << " " << ui << endl;

	// store collection of positive and negative integers in vi
	vector<int> vi;
	while (cin >> i)
		vi.push_back(i);

	// call absInt to store the absolute value of those ints in vu
	vector<unsigned> vu;
	transform(vi.begin(), vi.end(), back_inserter(vu), absInt());

	// print contents of vu using a lambda
	for_each(vu.begin(), vu.end(), [](unsigned i) { cout << i << " "; });
	cout << endl;

	vector<unsigned> vu2;
	// similar transformation but using a lambda
	transform(vi.begin(), vi.end(), back_inserter(vu2),
	          [](int i) { return i < 0 ? -i : i; });
	if (vu == vu2)
		cout << "as expected" << endl;
	else {
		cout << "something's wrong, vectors differ" << endl;
		for_each(vu.begin(), vu.end(), [](unsigned i) { cout << i << " "; });
	}
	cout << endl;

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x60, %rsp
leaq -0x64(%rbp), %rbx
movl $0xffffffd6, (%rbx)     # imm = 0xFFFFFFD6
movq 0x2d34(%rip), %rdi      # 0x3fd0
pushq $-0x2a
popq %rsi
callq 0x1120
leaq 0xd59(%rip), %rsi       # 0x2004
movq %rax, %rdi
callq 0x10d0
pushq $0x2a
popq %rsi
movq %rax, %rdi
callq 0x10a0
movq %rax, %rdi
callq 0x1070
xorps %xmm0, %xmm0
leaq -0x60(%rbp), %r14
movaps %xmm0, (%r14)
andq $0x0, 0x10(%r14)
movq 0x2d03(%rip), %r15      # 0x3fe0
movq %r15, %rdi
movq %rbx, %rsi
callq 0x1090
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x1303
movq %r14, %rdi
movq %rbx, %rsi
callq 0x148a
jmp 0x12dd
leaq -0x40(%rbp), %rdx
andq $0x0, 0x10(%rdx)
xorps %xmm0, %xmm0
movaps %xmm0, (%rdx)
movq -0x60(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq 0x14af
movq -0x40(%rbp), %r15
movq -0x38(%rbp), %r12
movq 0x2ca2(%rip), %rbx      # 0x3fd0
leaq 0xccf(%rip), %r14       # 0x2004
cmpq %r12, %r15
je 0x1356
movl (%r15), %esi
movq %rbx, %rdi
callq 0x10a0
movq %rax, %rdi
movq %r14, %rsi
callq 0x10d0
addq $0x4, %r15
jmp 0x1335
movq 0x2c73(%rip), %rdi      # 0x3fd0
callq 0x1070
xorps %xmm0, %xmm0
leaq -0x80(%rbp), %rbx
andq $0x0, 0x10(%rbx)
movaps %xmm0, (%rbx)
movq -0x60(%rbp), %r15
movq -0x58(%rbp), %r12
leaq -0x24(%rbp), %r14
cmpq %r12, %r15
je 0x13a0
movl (%r15), %eax
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
movl %ecx, -0x24(%rbp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1712
addq $0x4, %r15
jmp 0x137d
leaq -0x40(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x14fe
testb %al, %al
je 0x1402
movq 0x2c18(%rip), %rdi      # 0x3fd0
leaq 0xc47(%rip), %rsi       # 0x2006
callq 0x10d0
movq %rax, %rdi
callq 0x1070
movq 0x2bfd(%rip), %rdi      # 0x3fd0
callq 0x1070
leaq -0x80(%rbp), %rdi
callq 0x16d4
leaq -0x40(%rbp), %rdi
callq 0x16d4
leaq -0x60(%rbp), %rdi
callq 0x153c
xorl %eax, %eax
addq $0x60, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq 0x2bc7(%rip), %rdi      # 0x3fd0
leaq 0xc02(%rip), %rsi       # 0x2012
callq 0x10d0
movq %rax, %rdi
callq 0x1070
movq -0x40(%rbp), %r15
movq -0x38(%rbp), %r12
movq 0x2ba4(%rip), %rbx      # 0x3fd0
leaq 0xbd1(%rip), %r14       # 0x2004
cmpq %r12, %r15
je 0x13cc
movl (%r15), %esi
movq %rbx, %rdi
callq 0x10a0
movq %rax, %rdi
movq %r14, %rsi
callq 0x10d0
addq $0x4, %r15
jmp 0x1433
jmp 0x1468
jmp 0x145a
jmp 0x145a
movq %rax, %rbx
leaq -0x80(%rbp), %rdi
callq 0x16d4
jmp 0x146b
movq %rax, %rbx
leaq -0x40(%rbp), %rdi
callq 0x16d4
jmp 0x1479
movq %rax, %rbx
leaq -0x60(%rbp), %rdi
callq 0x153c
movq %rbx, %rdi
callq 0x1130