Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • C++

Idiom #242 Iterate over a set

Call a function f on each element e of a set x.

#include <algorithm>
std::for_each(x.begin(), x.end(), f);
for (auto e : x)
    f(e);

C++11 or later

If f is expected to change e as a side effect, replace auto with auto&
(doseq [e x]
  (f e))

New implementation...