Visual C++ 15.6 で並列 for_each
Visual Studio 2017の15.6からC++17から入るParallel Algorithmsが部分的に実装されました。 以下の並列for_eachコードが動きようになります。
#include <algorithm> #include <execution> #include <iostream> #include <vector> int main() { // サイズ10のvectorを作って0, 1, 2, ..., 9で埋める std::vector<int> v(10, 0); std::iota(v.begin(), v.end(), 0); // 要素の出力を並列に実行 std::for_each(std::execution::par, v.begin(), v.end(), [](int it) { std::cout << it << std::endl; }); }
実行結果例
71 3 24 06 8 9 5 Press any key to continue . . .
並列で実行されていることがわかると思います
Visual C++の実装状態