// File: 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
subq $0x1a0, %rsp            # imm = 0x1A0
movl $0x0, -0x4(%rbp)
leaq -0x29(%rbp), %rdi
movq %rdi, -0xd8(%rbp)
callq 0x1110
movq -0xd8(%rbp), %rdx
leaq 0xd54(%rip), %rsi       # 0x2004
leaq -0x28(%rbp), %rdi
callq 0x10d0
jmp 0x12bb
leaq -0x29(%rbp), %rdi
callq 0x10b0
leaq -0x61(%rbp), %rdi
movq %rdi, -0xe0(%rbp)
callq 0x1110
movq -0xe0(%rbp), %rdx
leaq 0xd2d(%rip), %rsi       # 0x200f
leaq -0x60(%rbp), %rdi
callq 0x10d0
jmp 0x12ed
leaq -0x61(%rbp), %rdi
callq 0x10b0
leaq -0x60(%rbp), %rdi
leaq -0x28(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x1080
movq %rax, -0x70(%rbp)
cmpq $-0x1, -0x70(%rbp)
je 0x13fb
movq 0x2cbb(%rip), %rdi      # 0x3fd8
leaq 0xcf0(%rip), %rsi       # 0x2014
callq 0x1090
movq %rax, -0xe8(%rbp)
jmp 0x1332
movq -0xe8(%rbp), %rdi
movq -0x70(%rbp), %rsi
callq 0x1030
movq %rax, -0xf0(%rbp)
jmp 0x134b
movq -0xf0(%rbp), %rdi
leaq 0xcd3(%rip), %rsi       # 0x202c
callq 0x1090
movq %rax, -0xf8(%rbp)
jmp 0x1367
movq -0x70(%rbp), %rsi
leaq -0x60(%rbp), %rdi
callq 0x1130
movq %rax, -0x100(%rbp)
jmp 0x137d
movq -0xf8(%rbp), %rdi
movq -0x100(%rbp), %rax
movsbl (%rax), %esi
callq 0x10c0
movq %rax, -0x108(%rbp)
jmp 0x139c
movq -0x108(%rbp), %rdi
movq 0x2c1e(%rip), %rsi      # 0x3fc8
callq 0x10a0
jmp 0x13b1
jmp 0x1447
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x29(%rbp), %rdi
callq 0x10b0
jmp 0x1789
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x61(%rbp), %rdi
callq 0x10b0
jmp 0x1780
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x1777
movq 0x2bd6(%rip), %rdi      # 0x3fd8
leaq 0xc30(%rip), %rsi       # 0x2039
callq 0x1090
movq %rax, -0x110(%rbp)
jmp 0x1417
movq -0x110(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x1070
movq %rax, -0x118(%rbp)
jmp 0x1430
movq -0x118(%rbp), %rdi
movq 0x2b8a(%rip), %rsi      # 0x3fc8
callq 0x10a0
jmp 0x1445
jmp 0x1447
movq $0x0, -0x70(%rbp)
movq -0x70(%rbp), %rdx
leaq -0x60(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x1080
movq %rax, -0x70(%rbp)
cmpq $-0x1, %rax
je 0x151a
movq 0x2b63(%rip), %rdi      # 0x3fd8
leaq 0xb98(%rip), %rsi       # 0x2014
callq 0x1090
movq %rax, -0x120(%rbp)
jmp 0x148a
movq -0x120(%rbp), %rdi
movq -0x70(%rbp), %rsi
callq 0x1030
movq %rax, -0x128(%rbp)
jmp 0x14a3
movq -0x128(%rbp), %rdi
leaq 0xb7b(%rip), %rsi       # 0x202c
callq 0x1090
movq %rax, -0x130(%rbp)
jmp 0x14bf
movq -0x70(%rbp), %rsi
leaq -0x60(%rbp), %rdi
callq 0x1130
movq %rax, -0x138(%rbp)
jmp 0x14d5
movq -0x130(%rbp), %rdi
movq -0x138(%rbp), %rax
movsbl (%rax), %esi
callq 0x10c0
movq %rax, -0x140(%rbp)
jmp 0x14f4
movq -0x140(%rbp), %rdi
movq 0x2ac6(%rip), %rsi      # 0x3fc8
callq 0x10a0
jmp 0x1509
movq -0x70(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x70(%rbp)
jmp 0x144f
leaq -0x91(%rbp), %rdi
movq %rdi, -0x148(%rbp)
callq 0x1110
movq -0x148(%rbp), %rdx
leaq 0xb0d(%rip), %rsi       # 0x2048
leaq -0x90(%rbp), %rdi
callq 0x10d0
jmp 0x1549
leaq -0x91(%rbp), %rdi
callq 0x10b0
leaq 0xaf8(%rip), %rsi       # 0x2054
movq %rsi, -0x158(%rbp)
xorl %eax, %eax
movl %eax, %edx
leaq -0x90(%rbp), %rdi
movq %rdi, -0x160(%rbp)
callq 0x1120
movq -0x160(%rbp), %rdi
movq -0x158(%rbp), %rsi
movq %rax, -0xa0(%rbp)
movq $-0x1, %rdx
callq 0x10f0
movq %rax, -0x150(%rbp)
jmp 0x15a4
movq -0x150(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq 0x2a1f(%rip), %rdi      # 0x3fd8
leaq 0xa99(%rip), %rsi       # 0x2059
callq 0x1090
movq %rax, -0x168(%rbp)
jmp 0x15ce
movq -0x168(%rbp), %rdi
movq -0xa0(%rbp), %rsi
callq 0x1030
movq %rax, -0x170(%rbp)
jmp 0x15ea
movq -0x170(%rbp), %rdi
leaq 0xa5f(%rip), %rsi       # 0x2057
callq 0x1090
movq %rax, -0x178(%rbp)
jmp 0x1606
movq -0x178(%rbp), %rdi
movq -0xa8(%rbp), %rsi
callq 0x1030
movq %rax, -0x180(%rbp)
jmp 0x1622
movq -0x180(%rbp), %rdi
movq 0x2998(%rip), %rsi      # 0x3fc8
callq 0x10a0
jmp 0x1637
leaq -0xc9(%rbp), %rdi
movq %rdi, -0x188(%rbp)
callq 0x1110
movq -0x188(%rbp), %rdx
leaq 0xa11(%rip), %rsi       # 0x2069
leaq -0xc8(%rbp), %rdi
callq 0x10d0
jmp 0x1666
leaq -0xc9(%rbp), %rdi
callq 0x10b0
xorl %eax, %eax
movl %eax, %edx
leaq -0xc8(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x1050
movq %rax, -0x70(%rbp)
movq 0x2947(%rip), %rdi      # 0x3fd8
leaq 0x9d9(%rip), %rsi       # 0x2071
callq 0x1090
movq %rax, -0x190(%rbp)
jmp 0x16a6
movq -0x190(%rbp), %rdi
movq -0x70(%rbp), %rsi
callq 0x1030
movq %rax, -0x198(%rbp)
jmp 0x16bf
movq -0x198(%rbp), %rdi
movq 0x28fb(%rip), %rsi      # 0x3fc8
callq 0x10a0
jmp 0x16d4
movl $0x0, -0x4(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x1040
leaq -0x90(%rbp), %rdi
callq 0x1040
leaq -0x60(%rbp), %rdi
callq 0x1040
leaq -0x28(%rbp), %rdi
callq 0x1040
movl -0x4(%rbp), %eax
addq $0x1a0, %rsp            # imm = 0x1A0
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x91(%rbp), %rdi
callq 0x10b0
jmp 0x1777
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x176b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0xc9(%rbp), %rdi
callq 0x10b0
jmp 0x176b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x1040
leaq -0x90(%rbp), %rdi
callq 0x1040
leaq -0x60(%rbp), %rdi
callq 0x1040
leaq -0x28(%rbp), %rdi
callq 0x1040
movq -0x38(%rbp), %rdi
callq 0x1100