Logo

Programming-Idioms

  • Rust
  • C++

Idiom #254 Replace value in list

Replace all exact occurrences of "foo" with "bar" in the string list x

std::replace(x.begin(), x.end(), "foo", "bar");
for v in &mut x {
    if *v == "foo" {
        *v = "bar";
    }
}
(replace {"foo" "bar"} x)

New implementation...