Range-based loop or for_each with execution policy better?

629 Views Asked by At

I've read about those new execution policies in C++17 on cppreference.com: https://en.cppreference.com/w/cpp/algorithm/execution_policy_tag_t

And I was wondering should we prefer those now over range-based loops if we want to allow the compiler to optimize to the best of its possibilities? I'm using gcc which doesn't implement them yet, so I can't test it, but for the future should I prefer this:

int a[] = {1,2};
std::for_each(std::execution::par_unseq, std::begin(a), std::end(a), [](int& p) {
  ++p;
});

Or this:

for(auto& p : a) {
  ++p;
}
0

There are 0 best solutions below