// File: /workspace/github_cpp_makefile_star2_O1/iZhangHui[P]CppPrimer/CH09_SequentialContainers/examples/erase1.cc
// Function: main
int main()
{
    list<string> slist;
    string s;
    while (cin >> s)
        slist.push_back(s);  // read the contents into slist

    /* we'll explain find in chapter 10
     * find looks in the sequence denoted by its first two
     * iterator arguments for the value of its third argument
     * returns an iterator to the first element with that value
     * if that element exists in the input sequence
     * otherwise returns the end iterator
     */
    auto iter = find(slist.begin(), slist.end(), "Quasimodo");
    if (iter != slist.end())
         slist.erase(iter);

    auto orig = slist; // keep a copy before we destroy the contents
    slist.clear();     // delete all the elements within the container
    cout << "after clear, size is: " << slist.size() << endl;

    slist = orig; // restore the data
    slist.erase(slist.begin(), slist.end()); // equivalent
    cout << "after erase begin to end, size is: " << slist.size() << endl;

    slist = orig; // restore the data
    auto elem1 = slist.begin(), elem2 = slist.end();
    // ++elem2;
    // ++elem2;

    /* delete the range of elements between two iterators
     * returns an iterator to the element just after the last removed element
     * after the call elem1 == elem2
     */
    elem1 = slist.erase(elem1, elem2);
    cout << "after erase elem1 to elem2 size is: " << slist.size() << endl;

    if (elem1 != elem2)
        cout << "somethings wrong" << endl;
    else
        cout << "okay, they're equal " << endl;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x50, %rsp
leaq -0x38(%rbp), %rbx
movq %rbx, 0x8(%rbx)
movq %rbx, (%rbx)
xorl %eax, %eax
movq %rax, 0x10(%rbx)
leaq -0x60(%rbp), %r12
movq %r12, -0x10(%r12)
movq %rax, -0x8(%r12)
movb $0x0, (%r12)
movq 0x2d0a(%rip), %r14      # 0x3fe0
leaq -0x70(%rbp), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x1110
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x130f
movq %rbx, %rdi
movq %r15, %rsi
callq 0x1608
movq %rax, %rdi
movq %rbx, %rsi
callq 0x1040
incq -0x28(%rbp)
jmp 0x12da
movq -0x38(%rbp), %r14
cmpq %rbx, %r14
je 0x1337
leaq 0xce5(%rip), %r15       # 0x2004
leaq 0x10(%r14), %rdi
movq %r15, %rsi
callq 0x1050
testl %eax, %eax
je 0x1337
movq (%r14), %r14
cmpq %rbx, %r14
jne 0x131f
cmpq %rbx, %r14
je 0x1348
leaq -0x38(%rbp), %rdi
movq %r14, %rsi
callq 0x16f4
leaq -0x50(%rbp), %rdi
leaq -0x38(%rbp), %rbx
movq %rbx, %rsi
callq 0x157c
movq %rbx, %rdi
callq 0x15b8
movq %rbx, -0x30(%rbp)
movq %rbx, -0x38(%rbp)
movq $0x0, -0x28(%rbp)
movq 0x2c59(%rip), %rdi      # 0x3fd0
leaq 0xc90(%rip), %rsi       # 0x200e
movl $0x16, %edx
callq 0x1100
movq -0x28(%rbp), %rsi
movq 0x2c3d(%rip), %rdi      # 0x3fd0
callq 0x1080
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 0x1090
leaq -0x50(%rbp), %rdx
movq (%rdx), %rsi
leaq -0x38(%rbp), %rbx
movq %rbx, %rdi
callq 0x177a
movq -0x38(%rbp), %rsi
cmpq %rbx, %rsi
je 0x13f1
movq (%rsi), %r14
movq %rbx, %rdi
callq 0x16f4
movq %r14, %rsi
cmpq %rbx, %r14
jne 0x13de
movq 0x2bd8(%rip), %rdi      # 0x3fd0
leaq 0xc26(%rip), %rsi       # 0x2025
movl $0x23, %edx
callq 0x1100
movq -0x28(%rbp), %rsi
movq 0x2bbc(%rip), %rdi      # 0x3fd0
callq 0x1080
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 0x1090
leaq -0x50(%rbp), %rdx
movq (%rdx), %rsi
leaq -0x38(%rbp), %rbx
movq %rbx, %rdi
callq 0x177a
movq -0x38(%rbp), %rsi
cmpq %rbx, %rsi
je 0x1472
movq (%rsi), %r14
movq %rbx, %rdi
callq 0x16f4
movq %r14, %rsi
cmpq %rbx, %r14
jne 0x145f
movq 0x2b57(%rip), %rdi      # 0x3fd0
leaq 0xbc9(%rip), %rsi       # 0x2049
movl $0x24, %edx
callq 0x1100
movq -0x28(%rbp), %rsi
movq 0x2b3b(%rip), %rdi      # 0x3fd0
callq 0x1080
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 0x1090
movq 0x2b05(%rip), %rbx      # 0x3fd0
leaq 0xb9c(%rip), %rsi       # 0x206e
movl $0x14, %edx
movq %rbx, %rdi
callq 0x1100
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x10d0
movsbl %al, %esi
movq 0x2ad3(%rip), %rdi      # 0x3fd0
callq 0x1030
movq %rax, %rdi
callq 0x1090
leaq -0x50(%rbp), %rdi
callq 0x15b8
movq -0x70(%rbp), %rdi
cmpq %r12, %rdi
je 0x1528
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x10f0
leaq -0x38(%rbp), %rdi
callq 0x15b8
xorl %eax, %eax
addq $0x50, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1552
jmp 0x1544
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0x15b8
jmp 0x1555
movq %rax, %rbx
movq -0x70(%rbp), %rdi
cmpq %r12, %rdi
je 0x156a
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x10f0
leaq -0x38(%rbp), %rdi
callq 0x15b8
movq %rbx, %rdi
callq 0x1140
nop