Suppose I have some function:
void mutate(V& v);
that reads/writes v -
and I want to write a function:
void mutate_map_values(std::multimap<K,V>& m, K k);
that applies mutate to all values of m that have key k.
What's the most succinct way to implement mutate_map_values in C++20?
.equal_rangeexample here: en.cppreference.com/w/cpp/container/multimap/equal_range . I'd like to know if there is a shorter way I am missing before I propose one to the C++ standards commitee.for_eachmember function might have been nice. But is it a common enough use-case that it should be added to the standard?for_eachworks becausemutateoperates onVnotstd::pair<K,V>.mutateis just a proxy for some code that does something with aV.equal_rangeinto theinitexpression of theforloop and use a structured binding such asfor (auto [i, e] = m.equal_range(key); i != e; ++i). Other than that it's difficult to judge without seeing an example of the code you would like to be able to write.