std::forward_list

cppreference.com

Example

print_list: (list: std::forward_list<int>) = {
    std::cout << "list: {";
    (copy comma: std::string = ())
    for list do (i) {
        std::cout << "(comma)$(i)$";
        comma = ", ";
    }
    std::cout << "}\n";
}

main: () = {
    ints: std::forward_list = (1, 2, 3, 4, 5);
    print_list(ints);
 
    // insert_after (pos, value)
    beginIt:= ints.begin();
    ints.insert_after(beginIt, -6);
    print_list(ints);
 
    // insert_after (pos, count, value)
    anotherIt:= beginIt;
    anotherIt++;
    anotherIt = ints.insert_after(anotherIt, 2 as size_t, -7);
    print_list(ints);
 
    // insert_after (pos, first, last)
    v: const std::vector = (-8, -9, -10);
    anotherIt = ints.insert_after(anotherIt, v.cbegin(), v.cend());
    print_list(ints);
 
    // insert_after (pos, initializer_list)
    x: std::initializer_list<int> = (-11, -12, -13, -14);
    ints.insert_after(anotherIt, x);
    print_list(ints);
}

Output

list: {1, 2, 3, 4, 5}
list: {1, -6, 2, 3, 4, 5}
list: {1, -6, -7, -7, 2, 3, 4, 5}
list: {1, -6, -7, -7, -8, -9, -10, 2, 3, 4, 5}
list: {1, -6, -7, -7, -8, -9, -10, -11, -12, -13, -14, 2, 3, 4, 5}

Back to top

cpp2reference.com licensed under CC-BY-SA and GFDL.