Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

6
  • Much better and clearer for using the standard library. Commented Jul 16, 2016 at 10:28
  • 4
    Because std::for-each(first, last, [&](auto& x) {if (p(x)) op(x); }); is totally simpler than for (Iter x = first; x != last; x++) if (p(x)) op(x);}? Commented Jul 17, 2016 at 10:44
  • 2
    @immibis reusing the standard library has other benefits, such as iterator validity checking, or (in C++17) being much easier to parallelize, simply by adding one more argument: std::for_each(std::execution::par, first, last, ...); How easy is it to add those things to a handwritten loop? Commented Jul 17, 2016 at 12:32
  • 2
    #pragma omp parallel for Commented Jul 18, 2016 at 10:18
  • 2
    @mark sorry, some random quirk of your source code or build chain made that annoyingly fragile parallel non-standard compiler extension generate zero performance boost with no diagnostic. Commented Jul 18, 2016 at 13:42