std::replace, std::replace_if

cppreference.com

Example

print_seq: (seq) = {
    for seq do (e) {
        std::cout << "(e)$ ";
    }
    std::cout << '\n';
}

main: () = {
    s: std::array = (5, 7, 4, 2, 8, 6, 1, 9, 0, 3);

    // Replace all occurrences of 8 with 88.
    std::replace(s.begin(), s.end(), 8, 88);
    print_seq(s);

    // Replace all values less than 5 with 55.
    std::replace_if(s.begin(), s.end(), :(i) i < 5, 55);
    print_seq(s);

    nums: std::array = (
        :std::complex<double>=(1, 3),
        :std::complex<double>=(1, 3));
    std::replace(nums.begin(), nums.end(),
                 std::complex<double>(1, 3),
                 std::complex<double>(4, 2));
    print_seq(nums);
}

Output

5 7 4 2 88 6 1 9 0 3 
5 7 55 55 88 6 55 9 55 55 
(4,2) (4,2) 

Back to top

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