// File: /workspace/github_cpp_makefile_star2_O2/iZhangHui[P]CppPrimer/CH09_SequentialContainers/examples/find_ops.cc
// Function: main
int main()
{
    string numbers("0123456789"), name("r2d2");
    // returns 1, i.e., the index of the first digit in name
    auto pos = name.find_first_of(numbers);
    if (pos != string::npos)
        cout << "found number at index: " << pos
             << " element is " << name[pos] << endl;
    else
        cout << "no number in: " << name << endl;

    pos = 0;
    // each iteration finds the next number in name
    while ((pos = name.find_first_of(numbers, pos))
                  != string::npos) {
        cout << "found number at index: " << pos
             << " element is " << name[pos] << endl;

        ++pos; // move to the next character
    }

    string river("Mississippi");

    auto first_pos = river.find("is");  // returns 1
    auto last_pos = river.rfind("is");  // returns 4
    cout << "find returned: " << first_pos
         << " rfind returned: " << last_pos << endl;

    string dept("03714p3");
    // returns 5, which is the index to the character 'p'
    pos = dept.find_first_not_of(numbers);
    cout << "first_not returned: " << pos << endl;

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
leaq 0xd9d(%rip), %rsi       # 0x2004
leaq -0x70(%rbp), %rdi
leaq -0x50(%rbp), %rdx
callq 0x1030
leaq 0xd94(%rip), %rsi       # 0x200f
leaq -0x50(%rbp), %rdi
leaq -0xb0(%rbp), %rdx
callq 0x1030
leaq -0x50(%rbp), %rdi
leaq -0x70(%rbp), %rsi
xorl %edx, %edx
callq 0x10a0
cmpq $-0x1, %rax
je 0x12e2
movq %rax, %rbx
movq 0x2d2e(%rip), %rdi      # 0x3fd8
leaq 0xd63(%rip), %rsi       # 0x2014
callq 0x10b0
movq %rax, %rdi
movq %rbx, %rsi
callq 0x1060
leaq 0xd64(%rip), %rsi       # 0x202c
movq %rax, %rdi
callq 0x10b0
movq -0x50(%rbp), %rcx
movsbl (%rcx,%rbx), %esi
movq %rax, %rdi
callq 0x10c0
jmp 0x1301
movq 0x2cef(%rip), %rdi      # 0x3fd8
leaq 0xd49(%rip), %rsi       # 0x2039
callq 0x10b0
leaq -0x50(%rbp), %rsi
movq %rax, %rdi
callq 0x1090
movq %rax, %rdi
callq 0x1050
xorl %r15d, %r15d
leaq -0x50(%rbp), %rbx
leaq -0x70(%rbp), %r14
leaq 0xcf9(%rip), %r13       # 0x2014
leaq 0xd0a(%rip), %r12       # 0x202c
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x10a0
cmpq $-0x1, %rax
je 0x137c
movq %rax, %r15
movq 0x2c98(%rip), %rdi      # 0x3fd8
movq %r13, %rsi
callq 0x10b0
movq %rax, %rdi
movq %r15, %rsi
callq 0x1060
movq %rax, %rdi
movq %r12, %rsi
callq 0x10b0
movq -0x50(%rbp), %rcx
movsbl (%rcx,%r15), %esi
movq %rax, %rdi
callq 0x10c0
movq %rax, %rdi
callq 0x1050
incq %r15
jmp 0x1322
leaq 0xcc5(%rip), %rsi       # 0x2048
leaq -0xb0(%rbp), %rdi
leaq -0x90(%rbp), %rdx
callq 0x1030
leaq 0xcb7(%rip), %rbx       # 0x2054
leaq -0xb0(%rbp), %r15
movq %r15, %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x1100
movq %rax, %r14
pushq $-0x1
popq %rdx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x10e0
movq %rax, %rbx
movq 0x2c0c(%rip), %rdi      # 0x3fd8
leaq 0xc86(%rip), %rsi       # 0x2059
callq 0x10b0
movq %rax, %rdi
movq %r14, %rsi
callq 0x1060
leaq 0xc6d(%rip), %rsi       # 0x2057
movq %rax, %rdi
callq 0x10b0
movq %rax, %rdi
movq %rbx, %rsi
callq 0x1060
movq %rax, %rdi
callq 0x1050
leaq 0xc5d(%rip), %rsi       # 0x2069
leaq -0x90(%rbp), %rdi
leaq -0x29(%rbp), %rdx
callq 0x1030
leaq -0x90(%rbp), %rdi
leaq -0x70(%rbp), %rsi
xorl %edx, %edx
callq 0x1070
movq %rax, %rbx
movq 0x2ba0(%rip), %rdi      # 0x3fd8
leaq 0xc32(%rip), %rsi       # 0x2071
callq 0x10b0
movq %rax, %rdi
movq %rbx, %rsi
callq 0x1060
movq %rax, %rdi
callq 0x1050
leaq -0x90(%rbp), %rdi
callq 0x1040
leaq -0xb0(%rbp), %rdi
callq 0x1040
leaq -0x50(%rbp), %rdi
callq 0x1040
leaq -0x70(%rbp), %rdi
callq 0x1040
xorl %eax, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x14b1
jmp 0x14c2
movq %rax, %rbx
jmp 0x14ce
movq %rax, %rbx
leaq -0x90(%rbp), %rdi
callq 0x1040
jmp 0x14b4
jmp 0x14c2
movq %rax, %rbx
leaq -0xb0(%rbp), %rdi
callq 0x1040
jmp 0x14c5
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0x1040
leaq -0x70(%rbp), %rdi
callq 0x1040
movq %rbx, %rdi
callq 0x10f0