void foo(int n)
{
// ...
}
int main()
{
std::vector<int> v{1, 2, 3, 4, 5, 6, 7};
// 순차 실행
std::for_each(v.begin(), v.end(), foo); // std::execution::seq 옵션
// 병렬로 실행
std::for_each(std::execution::par, v.begin(), v.end(), foo);
// 병렬로 실행(vectorized, SIMD)
std::for_each(std::execution::par_unseq, v.begin(), v.end(), foo);
// 싱글 스레드(vectorized, SIMD) C++ 20 부터
std::for_each(std::execution::unseq, v.begin(), v.end(), foo);
}
// 병렬 알고리즘은 C++17 부터 지원한다.